Changeset 2334 in MondoRescue for branches/2.2.10/mondo/src/mondorestore


Ignore:
Timestamp:
Aug 18, 2009, 5:28:18 PM (16 years ago)
Author:
Bruno Cornec
Message:

r3369@localhost: bruno | 2009-08-18 16:57:27 +0200

  • Transform bout 100 strcpy in dyn. allocation. Quality is improving
  • function figure_out_kernel_path_interactively_if_necessary now return a dynamically allocated string
  • mondoarchive checked with valgrind in text an newt modes
Location:
branches/2.2.10/mondo/src/mondorestore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/mondorestore/mondo-prep.c

    r2331 r2334  
    192192    char *incoming;
    193193    char *command;
    194     char *lvscan_sz;
    195     char *lvremove_sz;
    196     char *pvscan_sz;
    197     char *vgscan_sz;
    198     char *vgcreate_sz;
    199     char *vgchange_sz;
    200     char *vgremove_sz;
    201 //  char *do_this_last;
     194    char *lvscan_sz = NULL;
     195    char *lvremove_sz = NULL;
     196    char *pvscan_sz = NULL;
     197    char *vgscan_sz = NULL;
     198    char *vgchange_sz = NULL;
     199    char *vgremove_sz = NULL;
    202200
    203201    /** char **************************************************/
     
    229227    malloc_string(tmp);
    230228    malloc_string(incoming);
    231     malloc_string(lvscan_sz);
    232     malloc_string(lvremove_sz);
    233     malloc_string(vgscan_sz);
    234     malloc_string(pvscan_sz);
    235     malloc_string(vgcreate_sz);
    236     malloc_string(vgchange_sz);
    237     malloc_string(vgremove_sz);
    238     command = malloc(512);
     229    command = malloc(1024);
    239230
    240231    log_it("STARTING");
     
    243234    if (tmp1)   // found it :) cool
    244235    {
    245         strcpy(lvscan_sz, "lvm lvscan");
    246         strcpy(lvremove_sz, "lvm lvremove");
    247         strcpy(vgscan_sz, "lvm vgscan");
    248         strcpy(pvscan_sz, "lvm pvscan");
    249         strcpy(vgcreate_sz, "lvm vgcreate");
    250         strcpy(vgchange_sz, "lvm vgchange");
    251         strcpy(vgremove_sz, "lvm vgremove -f");
     236        mr_asprintf(lvscan_sz, "lvm lvscan");
     237        mr_asprintf(lvremove_sz, "lvm lvremove");
     238        mr_asprintf(vgscan_sz, "lvm vgscan");
     239        mr_asprintf(pvscan_sz, "lvm pvscan");
     240        mr_asprintf(vgchange_sz, "lvm vgchange");
     241        mr_asprintf(vgremove_sz, "lvm vgremove -f");
    252242    } else {
    253         strcpy(lvscan_sz, "lvscan");
    254         strcpy(lvremove_sz, "lvremove");
    255         strcpy(vgscan_sz, "vgscan");
    256         strcpy(pvscan_sz, "pvscan");
    257         strcpy(vgcreate_sz, "vgcreate");
    258         strcpy(vgchange_sz, "vgchange");
    259         strcpy(vgremove_sz, "vgremove");
     243        mr_asprintf(lvscan_sz, "lvscan");
     244        mr_asprintf(lvremove_sz, "lvremove");
     245        mr_asprintf(vgscan_sz, "vgscan");
     246        mr_asprintf(pvscan_sz, "pvscan");
     247        mr_asprintf(vgchange_sz, "vgchange");
     248        mr_asprintf(vgremove_sz, "vgremove");
    260249    }
    261250    mr_free(tmp1);
    262251
    263252    mr_asprintf(tmp1, "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> %s ; %s -f $i; done", lvscan_sz, MONDO_LOGFILE, lvremove_sz);
     253    mr_free(lvscan_sz);
     254    mr_free(lvremove_sz);
     255
    264256    run_program_and_log_output(tmp1, 5);
    265257    mr_free(tmp1);
    266258
    267259    sleep(1);
    268     sprintf(command,
    269             "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> %s ; done", vgscan_sz, vgchange_sz, vgremove_sz, MONDO_LOGFILE);
     260    sprintf(command, "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> %s ; done", vgscan_sz, vgchange_sz, vgremove_sz, MONDO_LOGFILE);
     261    mr_free(vgchange_sz);
     262    mr_free(vgremove_sz);
     263
    270264    run_program_and_log_output(command, 5);
    271265    if (just_erase_existing_volumes) {
     
    401395        sleep(1);
    402396    }
     397    mr_free(vgscan_sz);
     398    mr_free(pvscan_sz);
     399
    403400    paranoid_fclose(fin);
    404401    log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
     
    407404    paranoid_free(incoming);
    408405    paranoid_free(command);
    409     paranoid_free(lvscan_sz);
    410     paranoid_free(lvremove_sz);
    411     paranoid_free(vgscan_sz);
    412     paranoid_free(pvscan_sz);
    413     paranoid_free(vgcreate_sz);
    414     paranoid_free(vgchange_sz);
    415     paranoid_free(vgremove_sz);
    416406    system("sync");
    417407    system("sync");
     
    829819
    830820    if (res && strstr(program, "kludge")) {
    831         mr_asprintf(&tmp, "Kludge failed; using regular mkfs.%s to format %s", format, device);
     821        mr_asprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", format, device);
    832822        mr_free(program);
    833823#ifdef __FreeBSD__
     
    895885
    896886    assert(mountlist != NULL);
    897     mr_asprintf(tmp, "format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false");
    898     log_it(tmp);
    899     mr_free(tmp);
     887    log_it("format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false");
    900888
    901889    mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions     ");
     
    14231411    /** buffers *********************************************************/
    14241412    char *device_str = NULL;
    1425     char *format;
     1413    char *format = NULL;
    14261414    char *tmp = NULL;
    14271415
     
    14301418    assert(mountlist != NULL);
    14311419    assert_string_is_neither_NULL_nor_zerolength(drivename);
    1432 
    1433     malloc_string(format);
    14341420
    14351421    log_it("Partitioning drive %s", drivename);
     
    14451431    if (!pout_to_fdisk) {
    14461432        log_to_screen("Cannot call parted2fdisk to configure %s", drivename);
    1447         paranoid_free(format);
    14481433        return (1);
    14491434    }
     
    14801465                    mr_free(command);
    14811466                    mr_free(device_str);
    1482                     paranoid_free(format);
    14831467                    return r;
    14841468                }
     
    14951479                int i, line;
    14961480
    1497                 strcpy(format, "ufs");
     1481                mr_asprintf(format, "ufs");
    14981482                partsize = 0;
    14991483                for (i = 'a'; i < 'z'; ++i) {
     
    15521536#ifdef __FreeBSD__
    15531537        if (!fbsd_part) {
    1554 #endif
    1555 
    1556             strcpy(format, mountlist->el[lino].format);
     1538            mr_free(format);
     1539#endif
     1540
     1541            mr_asprintf(format, "%s", mountlist->el[lino].format);
    15571542            partsize = mountlist->el[lino].size;
    15581543
     
    15661551                ("You must leave at least one partition spare as the Extended partition.");
    15671552            mr_free(device_str);
    1568             paranoid_free(format);
     1553            mr_free(format);
    15691554            return (1);
    15701555        }
    15711556#endif
    15721557
    1573         retval +=
    1574             partition_device(pout_to_fdisk, drivename, current_devno,
    1575                              previous_devno, format, partsize);
     1558        retval += partition_device(pout_to_fdisk, drivename, current_devno, previous_devno, format, partsize);
     1559        mr_free(format);
    15761560
    15771561#ifdef __FreeBSD__
     
    16261610        }
    16271611    }
    1628     paranoid_free(format);
    16291612    return (retval);
    16301613}
     
    19781961        mr_asprintf(partcode, "");
    19791962    } else if (strlen(format) >= 1 && strlen(format) <= 2) {
    1980         mr_asprintf(partcode, format);
     1963        mr_asprintf(partcode, "%s", format);
    19811964    } else {
    19821965        /* probably an image */
     
    19851968        mr_free(tmp);
    19861969#ifdef __FreeBSD__
    1987         mr_asprintf(partcode, format);  // was a5
     1970        mr_asprintf(partcode, "%s", format);    // was a5
    19881971#else
    1989         mr_asprintf(partcode, format);  // was 83
     1972        mr_asprintf(partcode, "%s", format);    // was 83
    19901973#endif
    19911974    }
     
    22602243
    22612244    /** buffers *********************************************************/
    2262     char *tmp = NULL;
    22632245    char *program = NULL;
    22642246
     
    23112293        mr_asprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
    23122294#endif
    2313         mr_asprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, program);
    2314         log_it(tmp);
    2315         mr_free(tmp);
     2295        log_it("Unknown format (%s) - assuming '%s' will do", format, program);
    23162296        res = 0;
    23172297    }
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-compare.c

    r2332 r2334  
    4343
    4444  /** needs malloc *******/
    45     char *checksum_ptr;
    46     char *original_cksum_ptr;
    47     char *bigfile_fname_ptr;
     45    char *checksum_ptr = NULL;
     46    char *original_cksum_ptr = NULL;
     47    char *bigfile_fname_ptr = NULL;
    4848    char *tmp_ptr = NULL;
    4949    char *command_ptr = NULL;
    5050
    51     char *checksum, *original_cksum, *bigfile_fname, *tmp, *command;
     51    char *checksum, *bigfile_fname, *tmp, *command;
    5252
    5353    char *p;
     
    5858
    5959    malloc_string(checksum);
    60     malloc_string(original_cksum);
    6160    malloc_string(bigfile_fname);
    6261    malloc_string(tmp);
    6362    malloc_string(command);
    64     malloc_string(checksum_ptr);
    65     malloc_string(original_cksum_ptr);
    66     malloc_string(bigfile_fname_ptr);
    6763
    6864  /*********************************************************************
     
    7066   *********************************************************************/
    7167    assert(bkpinfo != NULL);
    72     memset(checksum_ptr, '\0', sizeof(checksum));
    73     memset(original_cksum_ptr, '\0', sizeof(original_cksum));
    74     memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
    7568  /** end **/
    7669
     
    8477    }
    8578    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
    86         log_to_screen("Cannot open bigfile %ld (%s)'s info file", bigfileno + 1, bigfile_fname_ptr);
     79        log_to_screen("Cannot open bigfile %ld (NULL)'s info file", bigfileno + 1);
    8780        return (1);
    8881    }
     
    9083    paranoid_fclose(fin);
    9184
    92     strcpy(checksum_ptr, biggiestruct.checksum);
    93     strcpy(bigfile_fname_ptr, biggiestruct.filename);
     85    mr_asprintf(checksum_ptr, "%s", biggiestruct.checksum);
     86    mr_asprintf(bigfile_fname_ptr, "%s", biggiestruct.filename);
    9487
    9588    log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
     
    10699    }
    107100    if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
    108         strcpy(original_cksum_ptr, "IGNORE");
    109101        log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname_ptr);
     102        mr_free(bigfile_fname_ptr);
    110103        return (1);
    111104    }
     
    122115    if (i) {
    123116        log_OS_error("Warning - command failed");
    124         original_cksum[0] = '\0';
    125117        return (1);
    126118    } else {
     
    128120            log_msg(2,
    129121                    "Unable to open /tmp/md5sum.txt; can't get live checksum");
    130             original_cksum[0] = '\0';
     122            mr_free(bigfile_fname_ptr);
    131123            return (1);
    132124        } else {
    133             fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin);
     125            mr_getline(original_cksum_ptr, fin);
    134126            paranoid_fclose(fin);
    135             for (i = strlen(original_cksum_ptr);
    136                  i > 0 && original_cksum[i - 1] < 32; i--);
    137             original_cksum[i] = '\0';
    138             p = (char *) strchr(original_cksum_ptr, ' ');
     127            p = strchr(original_cksum_ptr, ' ');
    139128            if (p) {
    140129                *p = '\0';
     
    143132    }
    144133    mr_asprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);
    145     if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) {
     134    if ((original_cksum_ptr != NULL) && (strcmp(checksum_ptr, original_cksum_ptr) == 0)) {
    146135        mr_strcat(tmp_ptr, " ... OK");
    147136    } else {
     
    149138        retval++;
    150139    }
     140    mr_free(checksum_ptr);
     141    mr_free(original_cksum_ptr);
     142
    151143    log_msg(1, tmp_ptr);
    152144    paranoid_free(tmp_ptr);
     
    159151        paranoid_fclose(fout);
    160152    }
    161 
    162     paranoid_free(original_cksum_ptr);
    163     paranoid_free(original_cksum);
    164     paranoid_free(bigfile_fname_ptr);
     153    mr_free(bigfile_fname_ptr);
     154
    165155    paranoid_free(bigfile_fname);
    166     paranoid_free(checksum_ptr);
    167156    paranoid_free(checksum);
    168157    paranoid_free(command);
     
    365354  /**  needs malloc **********/
    366355
    367     char *tarball_fname, *progress_str;
     356    char *tarball_fname = NULL;
     357    char *progress_str = NULL;
    368358    char *tmp = NULL;
    369359    char *mds = NULL;
     
    443433        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    444434    }
    445     paranoid_free(tarball_fname);
    446     paranoid_free(progress_str);
    447435    return (retval);
    448436}
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-newt.c

    r2332 r2334  
    7878    newtPushHelpLine
    7979        ("   Add one of the following unallocated RAID partitions to this RAID device.");
    80     mr_asprintf(&tmp, "%-26s %s", "Device", "Size");
     80    mr_asprintf(tmp, "%-26s %s", "Device", "Size");
    8181    headerMsg = newtLabel(1, 1, tmp);
    8282    partitionsListbox =
     
    104104
    105105            items = disklist->entries;
    106             strcpy(disklist->el[items].device,
    107                    unallocated_raid_partitions->el[currline].device);
     106            strcpy(disklist->el[items].device, unallocated_raid_partitions->el[currline].device);
    108107            disklist->el[items].index = index;
    109108            disklist->entries = ++items;
     
    154153
    155154    /** buffers **********************************************************/
    156     char drive_to_add[MAX_STR_LEN];
    157     char mountpoint_str[MAX_STR_LEN];
    158     char size_str[MAX_STR_LEN];
    159     char device_str[MAX_STR_LEN];
    160     char format_str[MAX_STR_LEN];
     155    char *drive_to_add = NULL;
     156    char *mountpoint_str = NULL;
     157    char *size_str = NULL;
     158    char *device_str = NULL;
     159    char *format_str = NULL;
    161160
    162161    /** pointers *********************************************************/
     
    171170    assert(keylist != NULL);
    172171
    173     strcpy(device_str, "/dev/");
    174     strcpy(mountpoint_str, "/");
     172    mr_asprintf(device_str, "/dev/");
     173    mr_asprintf(mountpoint_str, "/");
     174    mr_asprintf(size_str, "");
    175175#ifdef __FreeBSD__
    176     strcpy(format_str, "ufs");
     176    mr_asprintf(format_str, "ufs");
    177177#else
    178     strcpy(format_str, "ext3");
     178    mr_asprintf(format_str, "ext3");
    179179#endif
    180     size_str[0] = '\0';
    181180    newtOpenWindow(20, 5, 48, 10, "Add entry");
    182181    label0 = newtLabel(2, 1, "Device:    ");
     
    184183    label2 = newtLabel(2, 3, "Size (MB): ");
    185184    label3 = newtLabel(2, 4, "Format:    ");
    186     deviceComp =
    187         newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
    188     mountpointComp =
    189         newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
    190     formatComp =
    191         newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     185    deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     186    mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     187    formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
    192188    sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0);
    193189    bOK = newtButton(5, 6, "  OK  ");
     
    201197    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
    202198        b_res = newtRunForm(myForm);
    203         strcpy(device_str, device_here);
    204         strcpy(mountpoint_str, mountpoint_here);
    205         strcpy(format_str, format_here);
    206         strcpy(size_str, size_here);
    207 //      log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
     199        mr_free(device_str);
     200        mr_asprintf(device_str, "%s", device_here);
     201
     202        mr_free(mountpoint_str);
     203        mr_asprintf(mountpoint_str, "%s", mountpoint_here);
     204        mr_strip_spaces(mountpoint_str);
     205
     206        mr_free(format_str);
     207        mr_asprintf(format_str, "%s", format_here);
     208        mr_strip_spaces(format_str);
     209
     210        mr_free(size_str);
     211        mr_asprintf(size_str, "%s", size_here);
     212        mr_strip_spaces(size_str);
     213
    208214        strip_spaces(device_str);
    209         strip_spaces(mountpoint_str);
    210         strip_spaces(format_str);
    211         strip_spaces(size_str);
    212 //      log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str);
    213215        if (b_res == bOK) {
    214216            if (device_str[strlen(device_str) - 1] == '/') {
     
    216218                b_res = NULL;
    217219            }
    218             if (size_of_specific_device_in_mountlist(mountlist, device_str)
    219                 >= 0) {
     220            if (size_of_specific_device_in_mountlist(mountlist, device_str) >= 0) {
    220221                popup_and_OK("Can't add this - you've got one already!");
    221222                b_res = NULL;
     
    229230        return;
    230231    }
    231     strcpy(drive_to_add, device_str);
     232    mr_asprintf(drive_to_add, "%s", device_str);
    232233    for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--);
    233234    num_to_add = atoi(drive_to_add + i);
    234     drive_to_add[i] = '\0';
     235    mr_free(drive_to_add);
     236
    235237    currline = mountlist->entries;
    236238    strcpy(mountlist->el[currline].device, device_str);
    237239    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     240    mr_free(mountpoint_str);
     241
    238242    strcpy(mountlist->el[currline].format, format_str);
     243    mr_free(format_str);
     244
    239245    mountlist->el[currline].size = atol(size_str) * 1024L;
     246    mr_free(size_str);
     247
    240248    mountlist->entries++;
    241249    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
    242         initiate_new_raidlist_entry(raidlist, mountlist, currline,
    243                                     device_str);
    244     }
     250        initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str);
     251    }
     252    mr_free(device_str);
     253
    245254    redraw_mountlist(mountlist, keylist, listbox);
    246255}
     
    316325    /** buffers ***********************************************************/
    317326    char tmp = NULL;
    318 
    319 
    320 
     327    char *devname = NULL;
    321328
    322329    for (i = 0;
     
    324331         && strcmp(raidlist->el[i].volname, basename(raid_device)); i++);
    325332    if (i == raidlist->entries) {
    326         mr_asprintf(&tmp, "Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    327         log_it(tmp);
    328         mr_free(tmp);
     333        log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    329334        return (0);             // Isn't this more sensible than 999999999? If the raid dev !exists,
    330335        // then it has no size, right?
     
    338343        int k = 0, l = 0;
    339344        for (k = 0; k < raidrec->plex[j].subdisks; ++k) {
    340             char devname[64];
    341             strcpy(devname, raidrec->plex[j].sd[k].which_device);
     345            mr_asprintf(devname, "%s", raidrec->plex[j].sd[k].which_device);
    342346            for (l = 0; l < raidlist->disks.entries; ++l) {
    343347                if (!strcmp(devname, raidlist->disks.el[l].name)) {
     
    367371                }
    368372            }
     373            mr_free(devname);
    369374        }
    370375
     
    387392    }
    388393
    389     mr_asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device, (long) smallest_plex);
    390     log_it(tmp);
    391     mr_free(tmp);
     394    log_it("I have calculated %s's real size to be %ld", raid_device, (long) smallest_plex);
    392395    return (smallest_plex);
    393396#else
     
    406409    long sp = 0;
    407410
    408     /** buffers ***********************************************************/
    409     char tmp = NULL;
    410 
    411411    assert(mountlist != NULL);
    412412    assert(raidlist != NULL);
     
    417417         && strcmp(raidlist->el[i].raid_device, raid_device); i++);
    418418    if (i == raidlist->entries) {
    419         mr_asprintf(&tmp, "Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    420         log_it(tmp);
    421         mr_free(tmp);
     419        log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    422420        return (999999999);
    423421    }
     
    442440        total_size = smallest_partition * (noof_partitions - 1);
    443441    }
    444     mr_asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device, (long) total_size);
    445     log_it(tmp);
    446     mr_free(tmp);
     442    log_it("I have calculated %s's real size to be %ld", raid_device, (long) total_size);
    447443    return (total_size);
    448444#endif
     
    499495            }
    500496            p[i] = '\0';
    501             mr_free(sz);
    502497        }
    503498        if (!strcmp(p, "concat")) {
     
    568563            }
    569564            p[i] = '\0';
    570             mr_free(sz);
    571565        }
    572566        if (!strcmp(p, "linear")) {
     
    613607
    614608    /** buffers ***********************************************************/
    615     char *tmp = NULL;
    616 
    617609    assert(mountlist != NULL);
    618610    assert(raidlist != NULL);
     
    625617             pos++);
    626618        if (pos < mountlist->entries) {
    627             mr_asprintf(&tmp, "Deleting partition %s cos it was part of a now-defunct RAID", mountlist->el[pos].device);
    628             log_it(tmp);
    629             mr_free(tmp);
     619            log_it("Deleting partition %s cos it was part of a now-defunct RAID", mountlist->el[pos].device);
    630620
    631621            memcpy((void *) &mountlist->el[pos],
     
    662652    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    663653
    664     mr_asprintf(&tmp, "Delete %s from RAID device %s - are you sure?", disklist->el[currline].device, raid_device);
     654    mr_asprintf(tmp, "Delete %s from RAID device %s - are you sure?", disklist->el[currline].device, raid_device);
    665655    res = ask_me_yes_or_no(tmp);
    666656    mr_free(tmp);
     
    699689    /** buffers ***********************************************************/
    700690    char *tmp = NULL;
    701     char device[MAX_STR_LEN];
     691    char *device = NULL;
    702692
    703693
     
    707697    assert(keylist != NULL);
    708698
    709     /* BERLIOS: Why isn't device initialized here ? what is expected */
    710     pos =
    711         which_raid_device_is_using_this_partition(raidlist,
    712                                                   mountlist->el[currline].
    713                                                   device);
     699    pos = which_raid_device_is_using_this_partition(raidlist, mountlist->el[currline].device);
    714700    if (pos >= 0) {
    715         mr_asprintf(&tmp, "Cannot delete %s: it is in use by RAID device %s", mountlist->el[currline].device, raidlist->el[pos].OSSWAP(raid_device, volname));
     701        mr_asprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", mountlist->el[currline].device, raidlist->el[pos].OSSWAP(raid_device, volname));
    716702        popup_and_OK(tmp);
    717703        mr_free(tmp);
    718704        return;
    719705    }
    720     mr_asprintf(&tmp, "Delete %s - are you sure?", mountlist->el[currline].device);
     706    mr_asprintf(tmp, "Delete %s - are you sure?", mountlist->el[currline].device);
    721707    res = ask_me_yes_or_no(tmp);
    722708    mr_free(tmp);
     
    726712    }
    727713    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
    728         strcpy(device, mountlist->el[currline].device);
     714        mr_asprintf(device, "%s", mountlist->el[currline].device);
    729715        delete_raidlist_entry(mountlist, raidlist, device);
    730716        for (currline = 0;
     
    732718             && strcmp(mountlist->el[currline].device, device);
    733719             currline++);
     720        mr_free(device);
     721
    734722        if (currline == mountlist->entries) {
    735723            log_it("Dev is gone. I can't delete it. Ho-hum");
     
    775763        return;
    776764    }
    777     mr_asprintf(&tmp, "Do you want me to delete %s's partitions, too?", device);
     765    mr_asprintf(tmp, "Do you want me to delete %s's partitions, too?", device);
    778766    delete_partitions_too = ask_me_yes_or_no(tmp);
    779767    if (delete_partitions_too) {
     
    788776                    if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device,
    789777                                raidlist->disks.el[z].name)) {
    790                         strcpy(d.el[d.entries].name,
    791                                raidlist->disks.el[z].name);
    792                         strcpy(d.el[d.entries++].device,
    793                                raidlist->disks.el[z].device);
     778                        strcpy(d.el[d.entries].name, raidlist->disks.el[z].name);
     779                        strcpy(d.el[d.entries++].device, raidlist->disks.el[z].device);
    794780                    }
    795781                }
     
    844830
    845831    av = &raidrec->additional_vars;
    846     mr_asprintf(&tmp, "Delete %s - are you sure?", av->el[lino].label);
     832    mr_asprintf(tmp, "Delete %s - are you sure?", av->el[lino].label);
    847833    res = ask_me_yes_or_no(tmp);
    848834    mr_free(tmp);
     
    851837        if (!strcmp(av->el[lino].label, "persistent-superblock")
    852838            || !strcmp(av->el[lino].label, "chunk-size")) {
    853             mr_asprintf(&tmp, "%s must not be deleted. It would be bad.", av->el[lino].label);
     839            mr_asprintf(tmp, "%s must not be deleted. It would be bad.", av->el[lino].label);
    854840            popup_and_OK(tmp);
    855841            mr_free(tmp);
     
    920906                if (!warned_already) {
    921907                    warned_already = TRUE;
    922                     mr_asprintf(&tmp1, "Too many lines. Displaying first %d entries only. Close a directory to see more.", ARBITRARY_MAXIMUM);
     908                    mr_asprintf(tmp1, "Too many lines. Displaying first %d entries only. Close a directory to see more.", ARBITRARY_MAXIMUM);
    923909                    popup_and_OK(tmp1);
    924910                    mr_free(tmp1);
    925911                }
    926912            } else {
    927                 strcpy(g_strings_of_flist_window[lines_in_flist_window],
    928                        current_filename);
     913                strcpy(g_strings_of_flist_window[lines_in_flist_window], current_filename);
    929914                g_is_path_selected[lines_in_flist_window] = node->selected;
    930915                lines_in_flist_window++;
     
    941926                (g_strings_of_flist_window[i],
    942927                 g_strings_of_flist_window[i - 1]) < 0) {
    943                 mr_asprintf(&tmp1, g_strings_of_flist_window[i]);
    944                 strcpy(g_strings_of_flist_window[i],
    945                        g_strings_of_flist_window[i - 1]);
     928                mr_asprintf(tmp1, "%s", g_strings_of_flist_window[i]);
     929                strcpy(g_strings_of_flist_window[i], g_strings_of_flist_window[i - 1]);
    946930                strcpy(g_strings_of_flist_window[i - 1], tmp1);
    947931                mr_free(tmp1);
     
    10481032    void *curr_choice;
    10491033    void *keylist[ARBITRARY_MAXIMUM];
    1050 
    1051     /** buffers ***********************************************************/
    1052     char *tmp = NULL;
    10531034
    10541035    /** bool **************************************************************/
     
    10981079                indexno = 0;
    10991080            }
    1100             mr_asprintf(&tmp, "You selected '%s'", g_strings_of_flist_window[indexno]);
    1101             log_it(tmp);
    1102             mr_free(tmp);
     1081            log_it("You selected '%s'", g_strings_of_flist_window[indexno]);
    11031082
    11041083            if (b_res == bMore) {
     
    11931172
    11941173  /** buffers ***********************************************************/
    1195     char device_str[MAX_STR_LEN];
    1196     char mountpoint_str[MAX_STR_LEN];
    1197     char size_str[MAX_STR_LEN];
    1198     char format_str[MAX_STR_LEN];
     1174    char *device_str = NULL;
     1175    char *mountpoint_str = NULL;
     1176    char *size_str = NULL;
     1177    char *format_str = NULL;
    11991178    char *tmp = NULL;
    1200     char device_used_to_be[MAX_STR_LEN];
    1201     char mountpt_used_to_be[MAX_STR_LEN];
     1179    char *device_used_to_be = NULL;
     1180    char *mountpt_used_to_be = NULL;
    12021181
    12031182    /** pointers **********************************************************/
     
    12171196    memcpy((void *) &bkp_raidlist, (void *) raidlist,
    12181197           sizeof(struct raidlist_itself));
    1219     strcpy(device_str, mountlist->el[currline].device);
    1220     strcpy(device_used_to_be, mountlist->el[currline].device);
    1221     strcpy(mountpoint_str, mountlist->el[currline].mountpoint);
    1222     strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);
    1223     strcpy(format_str, mountlist->el[currline].format);
    1224     sprintf(size_str, "%lld", mountlist->el[currline].size / 1024L);
     1198    mr_asprintf(device_str, "%s", mountlist->el[currline].device);
     1199    mr_asprintf(device_used_to_be, "%s", mountlist->el[currline].device);
     1200    mr_asprintf(mountpoint_str, "%s", mountlist->el[currline].mountpoint);
     1201    mr_asprintf(mountpt_used_to_be, "%s", mountlist->el[currline].mountpoint);
     1202    mr_asprintf(format_str, "%s", mountlist->el[currline].format);
     1203    mr_asprintf(size_str, "%lld", mountlist->el[currline].size / 1024L);
    12251204    newtOpenWindow(20, 5, 48, 10, "Edit entry");
    12261205    label0 = newtLabel(2, 1, "Device:");
     
    12281207    label2 = newtLabel(2, 3, "Size (MB): ");
    12291208    label3 = newtLabel(2, 4, "Format:    ");
    1230     deviceComp =
    1231         newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
    1232     mountpointComp =
    1233         newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
    1234     formatComp =
    1235         newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
     1209    deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0);
     1210    mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0);
     1211    formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0);
    12361212    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    12371213        || !strcmp(mountlist->el[currline].mountpoint, "image")) {
     
    12531229    for (b_res = NULL; b_res != bOK && b_res != bCancel;) {
    12541230        b_res = newtRunForm(myForm);
    1255         strcpy(device_str, device_here);
    1256         strip_spaces(device_str);
    1257         strcpy(mountpoint_str, mountpoint_here);
    1258         strip_spaces(mountpoint_str);
    1259         strcpy(format_str, format_here);
    1260         strip_spaces(format_str);
     1231        mr_free(device_str);
     1232        mr_asprintf(device_str, "%s", device_here);
     1233        mr_strip_spaces(device_str);
     1234
     1235        mr_free(mountpoint_str);
     1236        mr_asprintf(mountpoint_str, "%s", mountpoint_here);
     1237        mr_strip_spaces(mountpoint_str);
     1238
     1239        mr_free(format_str);
     1240        mr_asprintf(format_str, "%s", format_here);
     1241        mr_strip_spaces(format_str);
     1242
    12611243        if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB)
    12621244            && strstr(device_used_to_be, RAID_DEVICE_STUB)
     
    12731255        if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    12741256            && strcmp(mountlist->el[currline].mountpoint, "image")) {
    1275             strcpy(size_str, size_here);
    1276             strip_spaces(size_str);
     1257            mr_free(size_str);
     1258            mr_asprintf(size_str, "%s", size_here);
     1259            mr_strip_spaces(size_str);
    12771260        } else {
    1278             sprintf(size_str, "%ld",
    1279                     calculate_raid_device_size(mountlist, raidlist,
    1280                                                mountlist->el[currline].
    1281                                                device) / 1024);
     1261            mr_asprintf(size_str, "%ld", calculate_raid_device_size(mountlist, raidlist, mountlist->el[currline].device) / 1024);
    12821262            newtLabelSetText(sizeComp, size_str);
    12831263        }
     
    12961276                                                 device);
    12971277                if (j < 0) {
    1298                     mr_asprintf(&tmp, "/etc/raidtab does not have an entry for %s; please delete it and add it again", mountlist->el[currline].device);
     1278                    mr_asprintf(tmp, "/etc/raidtab does not have an entry for %s; please delete it and add it again", mountlist->el[currline].device);
    12991279                    popup_and_OK(tmp);
    13001280                    mr_free(tmp);
     
    13101290    newtPopHelpLine();
    13111291    newtPopWindow();
     1292    mr_free(mountpt_used_to_be);
     1293
    13121294    if (b_res == bCancel) {
    13131295        memcpy((void *) raidlist, (void *) &bkp_raidlist,
    13141296               sizeof(struct raidlist_itself));
     1297        mr_free(device_str);
     1298        mr_free(device_used_to_be);
     1299        mr_free(format_str);
     1300        mr_free(size_str);
    13151301        return;
    13161302    }
    13171303    strcpy(mountlist->el[currline].device, device_str);
    13181304    strcpy(mountlist->el[currline].mountpoint, mountpoint_str);
     1305    mr_free(mountpoint_str);
     1306
    13191307    strcpy(mountlist->el[currline].format, format_str);
     1308    mr_free(format_str);
     1309
    13201310    if (strcmp(mountlist->el[currline].mountpoint, "image")) {
    13211311        if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) {
     
    13271317        }
    13281318    }
     1319    mr_free(size_str);
    13291320    newtListboxSetEntry(listbox, (long) keylist[currline],
    13301321                        mountlist_entry_to_string(mountlist, currline));
     
    13321323    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
    13331324        && !strstr(device_used_to_be, RAID_DEVICE_STUB)) {
    1334         initiate_new_raidlist_entry(raidlist, mountlist, currline,
    1335                                     device_str);
     1325        initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str);
    13361326    }
    13371327    /* if moving from RAID to non-RAID then do funky stuff */
     
    13501340#ifndef __FreeBSD__             /* It works fine under FBSD. */
    13511341    else if (strcmp(device_used_to_be, device_str)) {
    1352         popup_and_OK
    1353             ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
     1342        popup_and_OK("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it.");
    13541343    }
    13551344#endif
     1345    mr_free(device_str);
     1346    mr_free(device_used_to_be);
     1347
    13561348    redraw_mountlist(mountlist, keylist, listbox);
    13571349}
     
    13761368    for (i = 0; i < raidlist->disks.entries; ++i) {
    13771369        if (!strcmp(raidlist->disks.el[i].device, temp)) {
    1378             strcpy(raidrec->sd[raidrec->subdisks].which_device,
    1379                    raidlist->disks.el[i].name);
     1370            strcpy(raidrec->sd[raidrec->subdisks].which_device, raidlist->disks.el[i].name);
    13801371            found = TRUE;
    13811372        }
     
    14941485                switch (raidrec->plex[i].raidlevel) {
    14951486                case -1:
    1496                     mr_asprintf(&raidlevel, "concat");
     1487                    mr_asprintf(raidlevel, "concat");
    14971488                    break;
    14981489                case 0:
    1499                     mr_asprintf(&raidlevel, "striped");
     1490                    mr_asprintf(raidlevel, "striped");
    15001491                    break;
    15011492                case 5:
    1502                     mr_asprintf(&raidlevel, "raid5");
     1493                    mr_asprintf(raidlevel, "raid5");
    15031494                    break;
    15041495                default:
    1505                     mr_asprintf(&raidlevel, "raid%i", raidrec->plex[i].raidlevel);
     1496                    mr_asprintf(raidlevel, "raid%i", raidrec->plex[i].raidlevel);
    15061497                    break;
    15071498                }
    15081499
    15091500                if (raidrec->plex[i].raidlevel == -1) {
    1510                     mr_asprintf(&chunksize, "N/A");
     1501                    mr_asprintf(chunksize, "N/A");
    15111502                } else {
    1512                     mr_asprintf(&chunksize, "%dk", raidrec->plex[i].stripesize);
     1503                    mr_asprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
    15131504                }
    15141505                snprintf(pname, 64, "%s.p%i", raidrec->volname, i);
     
    15401531
    15411532        if (b_res == bDelete) {
    1542             mr_asprintf(&msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2);
     1533            mr_asprintf(msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2);
    15431534            res = ask_me_yes_or_no(msg);
    15441535            mr_free(msg);
     
    15781569    /** buffers ***********************************************************/
    15791570    char *title_of_editraidForm_window;
    1580     char *sz_raid_level;
     1571    char *sz_raid_level = NULL;
    15811572    char *sz_data_disks = NULL;
    15821573    char *sz_spare_disks = NULL;
     
    16001591    assert(raidrec != NULL);
    16011592
    1602     malloc_string(title_of_editraidForm_window);
    1603     malloc_string(sz_raid_level);
    1604 
    16051593    bkp_raidrec = mr_malloc(sizeof(struct raid_device_record));
    16061594    log_it("Started edit_raidlist_entry");
    16071595
    16081596    memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record));
    1609     sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
     1597    mr_asprintf(title_of_editraidForm_window, "%s", raidrec->raid_device);
    16101598    log_msg(2, "Opening newt window");
    16111599    newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window);
    16121600    for (;;) {
    16131601        log_msg(2, "Main loop");
    1614         sprintf(title_of_editraidForm_window, "Edit %s",
    1615                 raidrec->raid_device);
    1616         strcpy(sz_raid_level,
    1617                turn_raid_level_number_to_string(raidrec->raid_level));
     1602        mr_free(title_of_editraidForm_window);
     1603        mr_asprintf(title_of_editraidForm_window, "Edit %s", raidrec->raid_device);
     1604        mr_asprintf(sz_raid_level, "%s", turn_raid_level_number_to_string(raidrec->raid_level));
    16181605        /* Those 4 strings are allocated by the function  */
    16191606        sz_data_disks = number_of_disks_as_string(raidrec->data_disks.entries, "data");
     
    16661653    newtPopWindow();
    16671654    mountlist->el[currline].size = calculate_raid_device_size(mountlist, raidlist, raidrec->raid_device);
    1668     paranoid_free(title_of_editraidForm_window);
    1669     paranoid_free(sz_raid_level);
     1655    mr_free(title_of_editraidForm_window);
     1656    mr_free(sz_raid_level);
    16701657    paranoid_free(bkp_raidrec);
    16711658#endif
     
    17151702
    17161703    char *p = NULL;
     1704    char *tmp = NULL;
     1705    char *entry = NULL;
    17171706
    17181707    struct mountlist_itself *unallocparts;
     
    17301719    for (;;) {
    17311720        int i;
    1732         char headerstr[MAX_STR_LEN];
    1733         char tmp[64];
    1734         snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device");
    1735 
    17361721
    17371722        switch (raidrec->raidlevel) {
    17381723        case -1:
    1739             strcpy(tmp, "concat");
     1724            mr_asprintf(tmp, "concat");
    17401725            break;
    17411726        case 0:
    1742             strcpy(tmp, "striped");
     1727            mr_asprintf(tmp, "striped");
    17431728            break;
    17441729        case 5:
    1745             strcpy(tmp, "raid5");
     1730            mr_asprintf(tmp, "raid5");
    17461731            break;
    17471732        default:
    1748             sprintf(tmp, "unknown (%i)", raidrec->raidlevel);
     1733            mr_asprintf(tmp, "unknown (%i)", raidrec->raidlevel);
    17491734            break;
    17501735        }
    17511736        bLevel = newtCompactButton(2, 2, " RAID level ");
    17521737        sLevel = newtLabel(19, 2, tmp);
     1738        mr_free(tmp);
    17531739
    17541740        if (raidrec->raidlevel >= 0) {
    1755             sprintf(tmp, "%ik", raidrec->stripesize);
     1741            mr_asprintf(tmp, "%ik", raidrec->stripesize);
    17561742            bStripeSize = newtCompactButton(2, 4, " Stripe size ");
    17571743        } else {
    1758             strcpy(tmp, "N/A");
     1744            mr_asprintf(tmp, "N/A");
    17591745            bStripeSize = newtLabel(2, 4, "Stripe size:");
    17601746        }
    17611747        sStripeSize = newtLabel(19, 4, tmp);
     1748        mr_free(tmp);
    17621749
    17631750        bOK = newtCompactButton(2, 16, "  OK  ");
     
    17681755
    17691756
    1770         //  plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
    1771         //  plexesHeader  = newtLabel (2, 6, headerstr);
    17721757        unallocListbox =
    17731758            newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);
     
    17851770                                                 raidlist);
    17861771        for (i = 0; i < ARBITRARY_MAXIMUM; ++i) {
    1787             char entry[MAX_STR_LEN];
    17881772            keylist[i] = (void *) i;
    17891773            if (i < raidrec->subdisks) {
    1790                 snprintf(entry, MAX_STR_LEN, "%-17s",
    1791                          find_dev_entry_for_raid_device_name(raidlist,
    1792                                                              raidrec->
    1793                                                              sd[i].
    1794                                                              which_device));
     1774                mr_asprintf(entry, "%-17s", find_dev_entry_for_raid_device_name(raidlist, raidrec->sd[i].which_device));
    17951775                newtListboxAppendEntry(allocListbox, entry, keylist[i]);
     1776                mr_free(entry);
    17961777            }
    17971778            if (i < unallocparts->entries) {
    1798                 snprintf(entry, MAX_STR_LEN, "%-17s",
    1799                          unallocparts->el[i].device);
     1779                mr_asprintf(entry, "%-17s", unallocparts->el[i].device);
    18001780                newtListboxAppendEntry(unallocListbox, entry, keylist[i]);
     1781                mr_free(entry);
    18011782            }
    18021783        }
     
    18481829            choose_raid_level(raidrec);
    18491830        } else if (b_res == bStripeSize) {
    1850             char *tmp = NULL;
    1851 
    18521831            mr_asprintf(tmp, "%i", raidrec->stripesize);
    18531832            p = popup_and_get_string("Stripe size", "Please enter the stripe size in kilobytes.", tmp);
     
    19731952    bCancel = newtCompactButton(i += 12, 17, "Cancel");
    19741953    bOK = newtCompactButton(i += 12, 17, "  OK  ");
    1975     mr_asprintf(&tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format", "Size (MB)");
     1954    mr_asprintf(tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format", "Size (MB)");
    19761955    headerMsg = newtLabel(2, 1, tmp);
    19771956    flawsLabelA = newtLabel(2, 13, flaws_str_A);
     
    22382217#ifdef __FreeBSD__
    22392218    for (i = 0; i < raidlist->entries; i++) {
    2240         mr_asprintf(&vdev, "/dev/vinum/%s", raidlist->el[i].volname);
     2219        mr_asprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
    22412220        res = strcmp(device, vdev);
    22422221        mr_free(vdev);
     
    23652344    raidrec = &raidlist->el[pos_in_raidlist];
    23662345    initialize_raidrec(raidrec);
    2367     strcpy(raidrec->OSSWAP(raid_device, volname),
    2368            OSSWAP(device, basename(device)));
     2346    strcpy(raidrec->OSSWAP(raid_device, volname), OSSWAP(device, basename(device)));
    23692347#ifndef __FreeBSD__
    23702348    choose_raid_level(raidrec);
     
    26182596                                                   char *new_dev)
    26192597{
    2620     /** buffers ********************************************************/
    2621     char *tmp = NULL;
    2622 
    26232598    /** int ************************************************************/
    26242599    int pos = 0;
     
    26312606    pos = which_raid_device_is_using_this_partition(raidlist, old_dev);
    26322607    if (pos < 0) {
    2633         mr_asprintf(&tmp, "No need to rejig %s in raidlist: it's not listed.", old_dev);
    2634         log_it(tmp);
    2635         mr_free(tmp);
     2608        log_it("No need to rejig %s in raidlist: it's not listed.", old_dev);
    26362609    } else {
    26372610        if ((j =
     
    26392612                                         OSSWAP(el[pos].data_disks, disks),
    26402613                                         old_dev)) >= 0) {
    2641             strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].
    2642                    device, new_dev);
     2614            strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].device, new_dev);
    26432615        } else
    26442616            if ((j =
     
    26472619                                                    spares),
    26482620                                             old_dev)) >= 0) {
    2649             strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].
    2650                    device, new_dev);
     2621            strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].device, new_dev);
    26512622        }
    26522623#ifndef __FreeBSD__
     
    26652636#endif
    26662637        else {
    2667             mr_asprintf(&tmp, "%s is supposed to be listed in this raid dev but it's not...", old_dev);
    2668             log_it(tmp);
    2669             mr_free(tmp);
     2638            log_it("%s is supposed to be listed in this raid dev but it's not...", old_dev);
    26702639        }
    26712640    }
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-tools.c

    r2332 r2334  
    206206{
    207207
    208 /** needs malloc **/
    209208char *command = NULL;
    210 char *file;
    211 char *tmp;
     209char *file = NULL;
     210char *tmp = NULL;
    212211int res;
    213212
    214 malloc_string(file);
    215 malloc_string(tmp);
    216213assert_string_is_neither_NULL_nor_zerolength(f);
    217214assert_string_is_neither_NULL_nor_zerolength(list_fname);
     
    219216
    220217if (strncmp(preamble, f, strlen(preamble)) == 0) {
    221     strcpy(file, f + strlen(preamble));
     218    mr_asprintf(file, "%s", f + strlen(preamble));
    222219} else {
    223     strcpy(file, f);
     220    mr_asprintf(file, "%s", f);
    224221}
    225222if (file[0] == '/' && file[1] == '/') {
    226     strcpy(tmp, file);
    227     strcpy(file, tmp + 1);
     223    mr_asprintf(tmp, "%s", file);
     224    mr_free(file);
     225
     226    mr_asprintf(file, "%s", tmp + 1);
     227    mr_free(tmp);
    228228}
    229229log_msg(2, "Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file);
    230230mr_asprintf(command, "grep -E '^%s$' %s", file, list_fname);
     231mr_free(file);
     232
    231233res = run_program_and_log_output(command, FALSE);
    232234mr_free(command);
    233 paranoid_free(file);
    234 mr_free(tmp);
    235235if (res) {
    236236    return (FALSE);
     
    429429    }
    430430    if (res) {
    431         log_msg(1, "Unable to mount device %s (type %s) at %s", device,
    432                 format, mountdir);
     431        log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir);
    433432        log_msg(1, "command was '%s'", command);
    434433        if (!strcmp(mountpoint, "swap")) {
     
    479478char *tmp = NULL;
    480479char *these_failed = NULL;
    481 char *format;
    482480struct mountlist_itself *mountlist = NULL;
    483 
    484 malloc_string(format);
    485481
    486482assert(p_external_copy_of_mountlist != NULL);
     
    511507            update_progress_form(tmp);
    512508            mr_free(tmp);
    513             strcpy(format, mountlist->el[lino].format);
    514             res = mount_device(mountlist->el[lino].device,
    515                        mountlist->el[lino].mountpoint,
    516                        format, writeable);
     509            res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable);
     510
    517511            retval += res;
    518512            if (res) {
     
    556550    run_program_and_log_output("df -m", 3);
    557551    paranoid_free(mountlist);
    558     paranoid_free(format);
    559552    return (retval);
    560553}
     
    728721char *iso_path = NULL;
    729722char *old_isodir = NULL;
    730 char cfg_file[100];
     723char *cfg_file = NULL;
    731724t_bkptype media_specified_by_user;
    732725
     
    736729
    737730if (!cfgf) {
    738     strcpy(cfg_file, g_mondo_cfg_file);
     731    cfg_file = g_mondo_cfg_file;
    739732} else {
    740     strcpy(cfg_file, cfgf);
     733    cfg_file = cfgf;
    741734}
    742735
     
    14951488    char *conffile;
    14961489    char *tmp = NULL;
    1497     char *editor;
     1490    char *editor = NULL;
    14981491    char *p = NULL;
    14991492
     
    15011494    bool done;
    15021495
    1503     malloc_string(editor);
    15041496    malloc_string(rootdev);
    15051497    malloc_string(rootdrive);
    15061498    malloc_string(conffile);
    15071499    assert_string_is_neither_NULL_nor_zerolength(bd);
    1508     strcpy(editor, find_my_editor());
    15091500    mr_asprintf(boot_device, "%s", bd);
    15101501
     
    15441535                newtSuspend();
    15451536            }
     1537            mr_asprintf(editor, "%s", find_my_editor());
     1538
    15461539            mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    15471540            paranoid_system(tmp);
     
    15591552            paranoid_system(tmp);
    15601553            mr_free(tmp);
     1554            mr_free(editor);
    15611555
    15621556            if (!g_text_mode) {
     
    16111605    paranoid_free(rootdrive);
    16121606    paranoid_free(conffile);
    1613     paranoid_free(editor);
    16141607
    16151608    return (res);
     
    16311624    char *command = NULL;
    16321625    char *tmp = NULL;
    1633     char *editor;
     1626    char *editor = NULL;
    16341627
    16351628    int res;
    16361629    int done;
    16371630
    1638     malloc_string(editor);
    1639     strcpy(editor, find_my_editor());
    16401631    if (offer_to_run_stabelilo
    16411632        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
     
    16571648                    newtSuspend();
    16581649                }
     1650                mr_asprintf(editor, "%s", find_my_editor());
     1651
    16591652                mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
    16601653                paranoid_system(tmp);
     
    16641657                paranoid_system(tmp);
    16651658                mr_free(tmp);
     1659
     1660                mr_free(editor);
    16661661
    16671662                if (!g_text_mode) {
     
    16821677        res = TRUE;
    16831678    }
    1684     paranoid_free(editor);
    16851679    return (res);
    16861680}
     
    17011695    char *command = NULL;
    17021696    char *tmp = NULL;
    1703     char *editor;
     1697    char *editor = NULL;
    17041698
    17051699    int res;
    17061700    int done;
    17071701    bool run_lilo_M = FALSE;
    1708     malloc_string(editor);
    17091702
    17101703    if (!run_program_and_log_output
     
    17131706    }
    17141707
    1715     strcpy(editor, find_my_editor());
    17161708    if (offer_to_run_stablilo
    17171709        && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
     
    17331725                    newtSuspend();
    17341726                }
     1727                mr_asprintf(editor, "%s", find_my_editor());
     1728
    17351729                mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
    17361730                paranoid_system(tmp);
     
    17401734                paranoid_system(tmp);
    17411735                mr_free(tmp);
     1736
     1737                mr_free(editor);
    17421738
    17431739                if (!g_text_mode) {
     
    17951791                                   " lilo -M /dev/sda", 3);
    17961792    }
    1797     paranoid_free(editor);
    17981793    return (res);
    17991794}
     
    18211816    int done;
    18221817
    1823     malloc_string(editor);
    18241818    assert_string_is_neither_NULL_nor_zerolength(bd);
    18251819
    1826     strcpy(editor, find_my_editor());
    18271820    mr_asprintf(boot_device, "%s", bd);
    18281821
     
    18381831                    newtSuspend();
    18391832                }
     1833                mr_asprintf(editor, "%s", find_my_editor());
    18401834                mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
     1835                mr_free(editor);
     1836
    18411837                paranoid_system(tmp);
    18421838                mr_free(tmp);
     
    18841880        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    18851881    }
    1886     paranoid_free(editor);
    18871882    return (res);
    18881883}
  • branches/2.2.10/mondo/src/mondorestore/mondorestore.c

    r2331 r2334  
    443443    char *p = NULL;
    444444    char *tmp1 = NULL;
    445     char *fstab_fname;
     445    char *fstab_fname = NULL;
    446446    char *old_restpath = NULL;
    447447
     
    453453
    454454    malloc_string(tmp);
    455     malloc_string(fstab_fname);
    456455    assert(bkpinfo != NULL);
    457456    assert(mountlist != NULL);
     
    640639                            "Using tune2fs to identify your ext2,3,4 partitions");
    641640        if (does_file_exist("/tmp/fstab.new")) {
    642             strcpy(fstab_fname, "/tmp/fstab.new");
     641            mr_asprintf(fstab_fname, "/tmp/fstab.new");
    643642        } else {
    644             strcpy(fstab_fname, "/tmp/fstab");
     643            mr_asprintf(fstab_fname, "/tmp/fstab");
    645644        }
    646645        mr_asprintf(tmp1, "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
     646        mr_free(fstab_fname);
     647
    647648        res = system(tmp1);
    648649        mr_free(tmp1);
     
    665666  end_of_func:
    666667    paranoid_free(tmp);
    667     paranoid_free(fstab_fname);
    668668    log_it("Leaving interactive_mode()");
    669669    return (retval);
     
    10181018
    10191019  /** malloc ***/
    1020     char *checksum;
     1020    char *checksum = NULL;
    10211021    char *outfile_fname = NULL;
    10221022    char *tmp = NULL;
    10231023    char *bzip2_command = NULL;
    1024     char *ntfsprog_command, *suffix;
     1024    char *ntfsprog_command;
     1025    char *suffix = NULL;
    10251026    char *sz_devfile = NULL;
    10261027    char *bigblk;
    1027     char *p;
    10281028    char *mds = NULL;
    10291029    int retval = 0;
     
    10311031    long sliceno;
    10321032    long siz;
    1033     char ntfsprog_fifo[MAX_STR_LEN];
     1033    char *ntfsprog_fifo = NULL;
    10341034    char *file_to_openout = NULL;
    10351035    struct s_filename_and_lstat_info biggiestruct;
     
    10451045    assert(bkpinfo != NULL);
    10461046
    1047     malloc_string(checksum);
    10481047    malloc_string(ntfsprog_command);
    1049     malloc_string(suffix);
    10501048
    10511049    pathname_of_last_file_restored[0] = '\0';
     
    10671065    paranoid_fclose(fin);
    10681066
    1069     strcpy(checksum, biggiestruct.checksum);
    1070 
     1067    mr_asprintf(checksum, "%s", biggiestruct.checksum);
    10711068    if (!checksum[0]) {
    10721069        log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1);
    1073         p = checksum;
    1074     }
     1070    }
     1071    mr_free(checksum);
    10751072
    10761073    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
     
    10851082        node = find_string_at_node(filelist, biggiestruct.filename);
    10861083        if (!node) {
    1087             log_msg(0, "Skipping %s (name isn't in filelist)",
    1088                     biggiestruct.filename);
     1084            log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
    10891085            pathname_of_last_file_restored[0] = '\0';
    10901086            return (0);
    10911087        } else if (!(node->selected)) {
    1092             log_msg(1, "Skipping %s (name isn't in biggielist subset)",
    1093                     biggiestruct.filename);
     1088            log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
    10941089            pathname_of_last_file_restored[0] = '\0';
    10951090            return (0);
    10961091        }
    10971092    }
     1093
    10981094    /* otherwise, continue */
    1099 
    11001095    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
    11011096    if (biggiestruct.use_ntfsprog) {
    11021097        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
    1103             log_msg(1,
    1104                     "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
     1098            log_msg(1, "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
    11051099            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
    11061100            biggiestruct.use_ntfsprog = FALSE;
     
    11091103
    11101104    if (biggiestruct.use_ntfsprog)  // if it's an NTFS device
    1111 //  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
    11121105    {
    11131106        g_loglevel = 4;
     
    11161109        mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768));
    11171110        mkfifo(sz_devfile, 0x770);
    1118         strcpy(ntfsprog_fifo, sz_devfile);
     1111        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
    11191112        mr_free(sz_devfile);
    11201113        file_to_openout = ntfsprog_fifo;
     
    11231116            fatal_error("Fork failure");
    11241117        case 0:
    1125             log_msg(3,
    1126                     "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
    1127                     biggiestruct.filename, ntfsprog_fifo);
    1128             res =
    1129                 feed_outfrom_ntfsprog(biggiestruct.filename,
    1130                                        ntfsprog_fifo);
    1131 //          log_msg(3, "CHILD - fip - exiting");
     1118            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", biggiestruct.filename, ntfsprog_fifo);
     1119            res = feed_outfrom_ntfsprog(biggiestruct.filename, ntfsprog_fifo);
     1120            mr_free(ntfsprog_fifo);
    11321121            exit(res);
    11331122            break;
    11341123        default:
    1135             log_msg(3,
    1136                     "feed_into_ntfsprog() called in background --- pid=%ld",
    1137                     (long int) (pid));
    1138         }
     1124            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
     1125        }
     1126        mr_free(ntfsprog_fifo);
    11391127    } else {
    11401128        use_ntfsprog_hack = FALSE;
    1141         ntfsprog_fifo[0] = '\0';
    11421129        file_to_openout = outfile_fname;
    11431130        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    11551142     */
    11561143
    1157     strncpy(pathname_of_last_file_restored, biggiestruct.filename,
    1158             MAX_STR_LEN - 1);
     1144    strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN - 1);
    11591145    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
    11601146
     
    11671153
    11681154    for (sliceno = 1, finished = FALSE; !finished;) {
    1169         if (!does_file_exist
    1170             (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
    1171             &&
    1172             !does_file_exist(slice_fname
    1173                              (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
    1174             &&
    1175             !does_file_exist(slice_fname
    1176                              (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
    1177             &&
    1178             !does_file_exist(slice_fname
    1179                              (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    1180             log_msg(3,
    1181                     "Cannot find a data slice or terminator slice on CD %d",
    1182                     g_current_media_number);
     1155        if (!does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) &&
     1156            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo")) &&
     1157            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz")) &&
     1158            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1159            log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
    11831160            g_current_media_number++;
    11841161            mds = media_descriptor_string(bkpinfo->backup_media_type);
     
    11931170            mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
    11941171            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
    1195                 log_msg(2,
    1196                         "End of bigfile # %ld (slice %ld is the terminator)",
    1197                         bigfileno + 1, sliceno);
     1172                log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno);
    11981173                finished = TRUE;
    11991174                mr_free(tmp);
    12001175                continue;
    12011176            } else {
    1202                 if (does_file_exist
    1203                     (slice_fname
    1204                      (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
     1177                if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
    12051178                    mr_asprintf(bzip2_command, "lzop");
    1206                     strcpy(suffix, "lzo");
     1179                    mr_asprintf(suffix, "lzo");
    12071180                } else
    1208                     if (does_file_exist
    1209                         (slice_fname
    1210                          (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
     1181                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
    12111182                    mr_asprintf(bzip2_command, "gzip");
    1212                     strcpy(suffix, "gz");
     1183                    mr_asprintf(suffix, "gz");
    12131184                } else
    1214                     if (does_file_exist
    1215                         (slice_fname
    1216                          (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1185                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    12171186                    mr_asprintf(bzip2_command, "bzip2");
    1218                     strcpy(suffix, "bz2");
     1187                    mr_asprintf(suffix, "bz2");
    12191188                } else
    1220                     if (does_file_exist
    1221                         (slice_fname
    1222                          (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
     1189                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))) {
    12231190                    mr_asprintf(bzip2_command, "");
    1224                     strcpy(suffix, "");
     1191                    mr_asprintf(suffix, "");
    12251192                } else {
    12261193                    log_to_screen("OK, that's pretty fsck0red...");
     
    12351202                mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
    12361203            }
     1204            mr_free(suffix);
     1205
    12371206            mds = media_descriptor_string(bkpinfo->backup_media_type);
    12381207            mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", mds, g_current_media_number, bigfileno + 1, sliceno);
     
    12881257    mr_free(outfile_fname);
    12891258    paranoid_free(bigblk);
    1290     paranoid_free(checksum);
    12911259    paranoid_free(ntfsprog_command);
    1292     paranoid_free(suffix);
    12931260
    12941261    return (retval);
     
    13311298    char *ntfsprog_command;
    13321299    char *sz_devfile = NULL;
    1333     char *ntfsprog_fifo;
     1300    char *ntfsprog_fifo = NULL;
    13341301    char *file_to_openout = NULL;
    13351302
     
    13501317
    13511318    malloc_string(tmp);
    1352     malloc_string(ntfsprog_fifo);
    13531319    malloc_string(ntfsprog_command);
    13541320    old_loglevel = g_loglevel;
     
    14071373        mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
    14081374        mkfifo(sz_devfile, 0x770);
    1409         strcpy(ntfsprog_fifo, sz_devfile);
     1375        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
    14101376        mr_free(sz_devfile);
    14111377
     
    14171383            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
    14181384            res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
     1385            mr_free(ntfsprog_fifo);
    14191386            exit(res);
    14201387            break;
     
    14221389            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
    14231390        }
     1391        mr_free(ntfsprog_fifo);
    14241392    } else {
    14251393        if (!strncmp(orig_bf_fname, "/dev/", 5))    {
     
    14311399        }
    14321400        use_ntfsprog_hack = FALSE;
    1433         ntfsprog_fifo[0] = '\0';
    14341401        file_to_openout = outfile_fname;
    14351402        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    15391506    paranoid_free(tmp);
    15401507    paranoid_free(ntfsprog_command);
    1541     paranoid_free(ntfsprog_fifo);
    15421508    g_loglevel = old_loglevel;
    15431509    return (retval);
     
    20992065    char *tarball_fname = NULL;
    21002066    char *progress_str = NULL;
    2101     char *comment;
    2102 
    2103     malloc_string(comment);
    21042067
    21052068    assert(bkpinfo != NULL);
     
    21822145                mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
    21832146            }
    2184             strcpy(comment, tmp1);
     2147            if (attempts > 1) {
     2148                log_to_screen(tmp1);
     2149            }
    21852150            mr_free(tmp1);
    2186             if (attempts > 1) {
    2187                 log_to_screen(comment);
    2188             }
    21892151
    21902152            retval += res;
     
    22032165        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    22042166    }
    2205     paranoid_free(comment);
    22062167
    22072168    return (retval);
     
    26332594    struct raidlist_itself *raidlist;
    26342595    struct s_node *filelist;
    2635     char *a, *b;
     2596    char *tmp1 = NULL;
     2597    char *tmp2 = NULL;
    26362598    bool run_postnuke = FALSE;
    26372599
     
    26632625    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
    26642626
    2665     malloc_string(a);
    2666     malloc_string(b);
    26672627    setup_MR_global_filenames();    // malloc() and set globals, using bkpinfo->tmpdir etc.
    26682628    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
     
    27532713        toggle_path_selection(filelist, "/usr/share", TRUE);
    27542714        save_filelist(filelist, "/tmp/out.txt");
    2755         strcpy(a, argv[3]);
    2756         strcpy(b, argv[4]);
    2757 
    2758         res = save_filelist_entries_in_common(a, filelist, b, FALSE);
     2715        mr_asprintf(tmp1, "%s", argv[3]);
     2716        mr_asprintf(tmp2, "%s", argv[4]);
     2717
     2718        res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
     2719        mr_free(tmp1);
     2720        mr_free(tmp2);
     2721
    27592722        free_filelist(filelist);
    27602723        printf("res = %d", res);
     
    30292992    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
    30302993    free_libmondo_global_strings(); // it's fine to have this here :) really :)
    3031     paranoid_free(a);
    3032     paranoid_free(b);
    30332994
    30342995    unlink("/tmp/filelist.full");
Note: See TracChangeset for help on using the changeset viewer.