Ignore:
Timestamp:
Sep 25, 2013, 8:55:45 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Lots of memory management backports from 3.1 to 3.2 - still not finished, nor working ATM. the common subdir was done during travel, so this is essentially a backup !
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-files.c

    r3150 r3191  
    4747    /*@ buffers ***************************************************** */
    4848    static char output[MAX_STR_LEN];
    49     char command[MAX_STR_LEN * 2];
    50     char tmp[MAX_STR_LEN];
     49    char *command = NULL;
    5150
    5251    /*@ pointers **************************************************** */
    53     char *p;
     52    char *p = NULL;
    5453    char *q;
    5554    FILE *fin;
     
    6362    assert_string_is_neither_NULL_nor_zerolength(filename);
    6463    if (does_file_exist(filename)) {
    65         sprintf(command, "md5sum \"%s\"", filename);
     64        mr_asprintf(command, "md5sum \"%s\"", filename);
    6665        fin = popen(command, "r");
    6766        if (fin) {
     
    7372            paranoid_pclose(fin);
    7473        }
     74        mr_free(command);
    7575    } else {
    76         sprintf(tmp, "File '%s' not found; cannot calc checksum",
    77                 filename);
    78         log_it(tmp);
     76        log_it("File '%s' not found; cannot calc checksum", filename);
    7977    }
    8078    if (p) {
     
    130128
    131129    /*@ buffers ***************************************************** */
    132     char command[MAX_STR_LEN * 2];
    133     char incoming[MAX_STR_LEN];
    134     char tmp[MAX_STR_LEN];
    135     char *q;
     130    char *command = NULL;
     131    char *incoming = NULL;
    136132
    137133    /*@ long ******************************************************** */
     
    141137    FILE *fin;
    142138
    143     /*@ initialize [0] to null ******************************************** */
    144     incoming[0] = '\0';
    145 
    146139    assert_string_is_neither_NULL_nor_zerolength(filename);
    147140    if (!does_file_exist(filename)) {
    148         sprintf(tmp,
    149                 "%s does not exist, so I cannot found the number of lines in it",
    150                 filename);
    151         log_it(tmp);
     141        log_it("%s does not exist, so I cannot found the number of lines in it", filename);
    152142        return (0);
    153143    }
    154     sprintf(command, "cat %s | wc -l", filename);
     144    mr_asprintf(command, "cat %s | wc -l", filename);
    155145    if (!does_file_exist(filename)) {
     146        mr_free(command);
    156147        return (-1);
    157148    }
    158149    fin = popen(command, "r");
     150    mr_free(command);
     151
    159152    if (fin) {
    160153        if (feof(fin)) {
    161154            noof_lines = 0;
    162155        } else {
    163             q = fgets(incoming, MAX_STR_LEN - 1, fin);
    164             if (!q) {
    165                 // FIXME
    166             }
    167             while (strlen(incoming) > 0 && (q != NULL)
    168                    && incoming[strlen(incoming) - 1] < 32) {
     156            mr_getline(incoming, fin);
     157            while (strlen(incoming) > 0 && incoming[strlen(incoming) - 1] < 32) {
    169158                incoming[strlen(incoming) - 1] = '\0';
    170159            }
    171160            noof_lines = atol(incoming);
     161            mr_free(incoming);
    172162        }
    173163        paranoid_pclose(fin);
     
    215205void exclude_nonexistent_files(char *inout)
    216206{
    217     char infname[MAX_STR_LEN];
    218     char outfname[MAX_STR_LEN];
    219     char tmp[MAX_STR_LEN];
    220     char incoming[MAX_STR_LEN];
    221     char *q;
     207    char *infname = NULL;
     208    char *outfname = NULL;
     209    char *tmp = NULL;
     210    char *incoming = NULL;
    222211
    223212    /*@ int ********************************************************* */
     
    231220
    232221    assert_string_is_neither_NULL_nor_zerolength(inout);
    233     sprintf(infname, "%s.in", inout);
    234     sprintf(outfname, "%s", inout);
    235     sprintf(tmp, "cp -f %s %s", inout, infname);
     222    mr_asprintf(infname, "%s.in", inout);
     223    mr_asprintf(tmp, "cp -f %s %s", inout, infname);
    236224    run_program_and_log_output(tmp, FALSE);
     225    mr_free(tmp);
     226
    237227    if (!(fin = fopen(infname, "r"))) {
    238228        log_OS_error("Unable to openin infname");
     229        mr_free(infname);
    239230        return;
    240231    }
     232
     233    mr_asprintf(outfname, "%s", inout);
    241234    if (!(fout = fopen(outfname, "w"))) {
    242235        log_OS_error("Unable to openout outfname");
     236        mr_free(infname);
     237        mr_free(outfname);
    243238        return;
    244239    }
    245     for (q = fgets(incoming, MAX_STR_LEN, fin); !feof(fin) && (q != NULL);
    246          q = fgets(incoming, MAX_STR_LEN, fin)) {
     240    mr_free(outfname);
     241
     242    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    247243        i = strlen(incoming) - 1;
    248244        if (i >= 0 && incoming[i] < 32) {
     
    252248            fprintf(fout, "%s\n", incoming);
    253249        } else {
    254             sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);
    255             log_it(tmp);
    256         }
    257     }
     250            log_it("Excluding '%s'-nonexistent\n", incoming);
     251        }
     252        mr_free(incoming);
     253    }
     254    mr_free(incoming);
     255
    258256    paranoid_fclose(fout);
    259257    paranoid_fclose(fin);
    260258    unlink(infname);
    261 }
    262 
    263 
    264 
    265 
    266 
    267 
    268 
     259    mr_free(infname);
     260}
    269261
    270262
     
    278270int figure_out_kernel_path_interactively_if_necessary(char *kernel)
    279271{
    280     char tmp[MAX_STR_LEN];
    281     char *command;
     272    char *tmp = NULL;
     273    char *command = NULL;
    282274
    283275    if (!kernel[0]) {
    284         strcpy(kernel,
    285                call_program_and_get_last_line_of_output
    286                ("mindi --findkernel 2> /dev/null"));
     276        strcpy(kernel, call_program_and_get_last_line_of_output("mindi --findkernel 2> /dev/null"));
    287277    }
    288278    // If we didn't get anything back, check whether mindi raised a fatal error
    289279    if (!kernel[0]) {
    290         malloc_string(command);
    291         strcpy(command, "grep 'Fatal error' /var/log/mindi.log");
    292         strcpy(tmp, call_program_and_get_last_line_of_output(command));
     280        mr_asprintf(command, "%s", "grep 'Fatal error' /var/log/mindi.log");
     281        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    293282        if (strlen(tmp) > 1) {
    294283            popup_and_OK(tmp);
     284            mr_free(tmp);
     285            mr_free(command);
    295286            fatal_error("Mindi gave a fatal error. Please check '/var/log/mindi.log'.");
    296287        }
    297         paranoid_free(command);
     288        mr_free(tmp);
     289        mr_free(command);
    298290    }
    299291    log_it("Calling Mindi with kernel path of '%s'", kernel);
     
    310302                ("Kernel not found. Please specify with the '-k' flag.");
    311303        }
    312         sprintf(tmp, "User says kernel is at %s", kernel);
    313         log_it(tmp);
     304        log_it("User says kernel is at %s", kernel);
    314305    }
    315306    return (0);
    316307}
    317 
    318 
    319 
    320 
    321308
    322309
     
    334321    /*@ buffers ********************* */
    335322    static char output[MAX_STR_LEN];
    336     char *incoming;
    337     char *command;
    338 
    339     malloc_string(incoming);
    340     malloc_string(command);
    341     incoming[0] = '\0';
     323    char *incoming = NULL;
     324    char *command = NULL;
     325
    342326    /*@******************************* */
    343327
    344328    assert_string_is_neither_NULL_nor_zerolength(fname);
    345     sprintf(command, "which %s 2> /dev/null", fname);
    346     strcpy(incoming, call_program_and_get_last_line_of_output(command));
     329    mr_asprintf(command, "which %s 2> /dev/null", fname);
     330    mr_asprintf(incoming, call_program_and_get_last_line_of_output(command));
     331    mr_free(command);
     332
    347333    if (incoming[0] == '\0') {
    348334        if (system("which file > /dev/null 2> /dev/null")) {
    349             paranoid_free(incoming);
    350             paranoid_free(command);
     335            mr_free(incoming);
    351336            output[0] = '\0';
    352337            return (NULL);      // forget it :)
    353338        }
    354         sprintf(command,
    355                 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null",
    356                 incoming);
    357         strcpy(incoming,
    358                call_program_and_get_last_line_of_output(command));
    359     }
    360     if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    361     {
    362         sprintf(command, "dirname %s 2> /dev/null", incoming);
    363         strcpy(incoming,
    364                call_program_and_get_last_line_of_output(command));
     339        mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming);
     340        mr_free(incomig);
     341
     342        mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command));
     343        mr_free(command);
     344    }
     345    if (incoming[0] == '\0') {
     346        mr_asprintf(command, "dirname %s 2> /dev/null", incoming);
     347        mr_free(incoming);
     348
     349        mr_asprintf(incoming, "%s", call_program_and_get_last_line_of_output(command));
     350        mr_free(command);
    365351    }
    366352    strcpy(output, incoming);
    367353    if (output[0] != '\0' && does_file_exist(output)) {
    368         log_msg(4, "find_home_of_exe () --- Found %s at %s", fname,
    369                 incoming);
     354        log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, incoming);
    370355    } else {
    371356        output[0] = '\0';
    372357        log_msg(4, "find_home_of_exe() --- Could not find %s", fname);
    373358    }
    374     paranoid_free(incoming);
    375     paranoid_free(command);
     359    mr_free(incoming);
    376360    if (!output[0]) {
    377361        return (NULL);
     
    382366
    383367
    384 
    385 
    386 
    387 
    388 
    389 
    390368/**
    391369 * Get the last sequence of digits surrounded by non-digits in the first 32k of
     
    421399    for (; len > 0 && isdigit(datablock[len - 1]); len--);
    422400    trackno = atoi(datablock + len);
    423     /*
    424        sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);
    425        log_it(tmp);
    426      */
    427401    return (trackno);
    428402}
     
    444418
    445419    /*@ buffers ***************************************************** */
    446     char tmp[MAX_STR_LEN];
    447     char lastline[MAX_STR_LEN];
    448     char command[MAX_STR_LEN];
     420    char *lastline = NULL;
     421    char *command = NULL;
    449422    /*@ pointers **************************************************** */
    450     char *p;
     423    char *p = NULL;
    451424
    452425    /*@ int's ******************************************************* */
    453     int i;
    454 
    455     for (i = NOOF_ERR_LINES - 1;
    456          i >= 0 && !strstr(err_log_lines[i], "% Done")
    457          && !strstr(err_log_lines[i], "% done"); i--);
     426    int i = 0;
     427
     428    for (i = NOOF_ERR_LINES - 1; i >= 0 && !strstr(err_log_lines[i], "% Done") && !strstr(err_log_lines[i], "% done"); i--);
    458429    if (i < 0) {
    459         sprintf(command,
    460                 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'",
    461                 filename, '%');
    462         strcpy(lastline,
    463                call_program_and_get_last_line_of_output(command));
     430        mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%');
     431        mr_asprintf(lastline, "%s", call_program_and_get_last_line_of_output(command));
     432        mr_free(command);
    464433        if (!lastline[0]) {
     434            mr_free(lastline);
    465435            return (0);
    466436        }
    467437    } else {
    468         strcpy(lastline, err_log_lines[i]);
     438        mr_asprintf(lastline, "%s", err_log_lines[i]);
    469439    }
    470440
     
    472442    if (p) {
    473443        *p = '\0';
    474     }
    475 //  log_msg(2, "lastline='%s', ", p, lastline);
    476     if (!p) {
     444    } else {
     445        mr_free(lastline);
    477446        return (0);
    478447    }
    479     *p = '\0';
    480     for (p--; *p != ' ' && p != lastline; p--);
     448
     449    for (p--; isdigit(*p) && p != lastline; p--);
    481450    if (p != lastline) {
    482451        p++;
    483452    }
    484453    i = atoi(p);
    485 
    486     sprintf(tmp, "'%s' --> %d", p, i);
    487 //     log_to_screen(tmp);
    488 
     454    mr_free(lastline);
    489455    return (i);
    490456}
     
    504470    /*@ buffers ***************************************************** */
    505471    static char output[MAX_STR_LEN];
    506     static char command[MAX_STR_LEN * 2];
    507     static char tmp[MAX_STR_LEN];
    508     char *p = NULL;
     472    char *command = NULL;
    509473
    510474    /*@ pointers **************************************************** */
     
    514478
    515479    if (!does_file_exist(filename)) {
    516         sprintf(tmp, "Tring to get last line of nonexistent file (%s)",
    517                 filename);
    518         log_it(tmp);
     480        log_it("Tring to get last line of nonexistent file (%s)", filename);
    519481        output[0] = '\0';
    520482        return (output);
    521483    }
    522     sprintf(command, "tail -n1 %s", filename);
     484    mr_asprintf(command, "tail -n1 %s", filename);
    523485    fin = popen(command, "r");
     486    mr_free(command);
    524487    p = fgets(output, MAX_STR_LEN, fin);
    525488    if (p == NULL) {
     
    564527 * @bug I don't know what this function does. However, it seems orphaned, so it should probably be removed.
    565528 */
    566 int
    567 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath)
    568 {
     529int make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) {
    569530    /*@ pointers **************************************************** */
    570531    FILE *fin;
     
    577538
    578539    /*@ buffer ****************************************************** */
    579     char stub_fname[1000];
    580     char curr_fname[1000];
    581     char curr_cksum[1000];
    582     char tmp[1000];
    583     char *q;
     540    char *stub_fname = NULL;
     541    char *curr_fname = NULL;
     542    char *curr_cksum = NULL;
     543    char *tmp = NULL;
    584544
    585545    /*@ long [long] ************************************************* */
     
    595555    start_time = get_time();
    596556    filelist_length = length_of_file(filelist);
    597     sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);
    598     log_it(tmp);
     557    log_it("filelist = %s; cksumlist = %s", filelist, cksumlist);
     558
    599559    fin = fopen(filelist, "r");
    600560    if (fin == NULL) {
     
    610570        return (1);
    611571    }
    612     for (q = fgets(stub_fname, 999, fin); !feof(fin) && (q != NULL);
    613          q = fgets(stub_fname, 999, fin)) {
     572    for (mr_getline(stub_fname, fin); !feof(fin); mr_getline(stub_fname, fin)) {
    614573        if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) {
    615574            stub_fname[i] = '\0';
    616575        }
    617         sprintf(tmp, "%s%s", comppath, stub_fname);
    618         strcpy(curr_fname, tmp + 1);
    619         strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));
     576        mr_asprintf(tmp, "%s%s", comppath, stub_fname);
     577        mr_free(stub_fname);
     578
     579        mr_asprintf(curr_fname, "%s", tmp + 1);
     580        mr_free(tmp);
     581
     582        mr_asprintf(curr_cksum, "%s", calc_file_ugly_minichecksum(curr_fname));
    620583        fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);
     584        mr_free(curr_cksum);
     585
    621586        if (counter++ > 12) {
    622587            current_time = get_time();
    623588            counter = 0;
     589            /* BERLIOS: 37 really ? */
    624590            curr_fname[37] = '\0';
    625591            curr_pos = ftello(fin) / 1024;
    626592            percentage = (int) (curr_pos * 100 / filelist_length);
    627593            time_taken = current_time - start_time;
    628             if (percentage == 0) {
    629                 /*              printf("%0d%% done      \r",percentage); */
    630             } else {
    631                 time_remaining =
    632                     time_taken * 100 / (long) (percentage) - time_taken;
    633                 sprintf(tmp,
    634                         "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r",
    635                         percentage, (int) (time_taken / 60),
    636                         (int) (time_taken % 60),
    637                         (int) (time_remaining / 60),
    638                         (int) (time_remaining % 60), curr_fname);
    639                 log_to_screen(tmp);
     594            if (percentage != 0) {
     595                time_remaining = time_taken * 100 / (long) (percentage) - time_taken;
     596                log_to_screen("%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r", percentage, (int) (time_taken / 60), (int) (time_taken % 60), (int) (time_remaining / 60), (int) (time_remaining % 60), curr_fname);
    640597            }
    641598            sync();
    642599        }
    643     }
     600        mr_free(curr_fname);
     601    }
     602    mr_free(stub_fname);
     603
    644604    paranoid_fclose(fout);
    645605    paranoid_fclose(fin);
     
    654614 * @return The return value of @c mkdir.
    655615 */
    656 int make_hole_for_dir(char *outdir_fname)
    657 {
    658     char tmp[MAX_STR_LEN * 2];
     616int make_hole_for_dir(const char *outdir_fname)
     617{
     618    char *tmp = NULL;
    659619    int res = 0;
    660620
    661621    assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
    662     sprintf(tmp, "mkdir -p %s", outdir_fname);
     622    mr_asprintf(tmp, "mkdir -p %s", outdir_fname);
    663623    res = system(tmp);
     624    mr_free(tmp);
    664625    return (res);
    665626}
     
    675636{
    676637    /*@ buffer ****************************************************** */
    677     char command[MAX_STR_LEN * 2];
     638    char *command = NULL;
    678639
    679640    /*@ int  ******************************************************** */
     
    685646    assert(!strstr(outfile_fname, MNT_CDROM));
    686647    assert(!strstr(outfile_fname, "/dev/cdrom"));
    687     sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
     648    mr_asprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
    688649    res += system(command);
    689     sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
     650    mr_free(command);
     651
     652    mr_asprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
    690653    res += system(command);
    691     sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
     654    mr_free(command);
     655
     656    mr_asprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
    692657    res += system(command);
     658    mr_free(command);
     659
    693660    unlink(outfile_fname);
    694661    return (0);
    695662}
    696 
    697 
    698663
    699664
     
    713678
    714679    /*@ buffers **************************************************** */
    715     char incoming[MAX_STR_LEN];
    716     char *p = NULL;
     680    char *incoming = NULL;
    717681
    718682    /*@ end vars *************************************************** */
     
    725689        return (0);
    726690    }
    727     p = fgets(incoming, MAX_STR_LEN - 1, fin);
    728     while (!feof(fin) && (p != NULL)) {
     691    mr_getline(incoming, fin);
     692    while (!feof(fin)) {
    729693        if (strstr(incoming, wildcard)) {
    730694            matches++;
    731695        }
    732         p = fgets(incoming, MAX_STR_LEN - 1, fin);
    733     }
     696        mr_free(incoming);
     697        mr_getline(incoming, fin);
     698    }
     699    mr_free(incoming);
    734700    paranoid_fclose(fin);
    735701    return (matches);
     
    746712long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
    747713{
    748     char command[MAX_STR_LEN];
    749     char mountlist[MAX_STR_LEN];
    750     char sz_res[MAX_STR_LEN];
     714    char *command = NULL;
     715    char *mountlist = NULL;
     716    char *sz_res = NULL;
    751717    long file_len_K;
    752718
    753     sprintf(mountlist, "%s/mountlist.txt", tmpdir);
    754     sprintf(command,
    755             "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'",
    756             dev, tmpdir);
     719    mr_asprintf(mountlist, "%s/mountlist.txt", tmpdir);
     720    mr_asprintf(command, "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'", dev, tmpdir);
     721    mr_free(mountlist);
     722
    757723    log_it(command);
    758     strcpy(sz_res, call_program_and_get_last_line_of_output(command));
     724    mr_asprintf(sz_res, "%s", call_program_and_get_last_line_of_output(command));
    759725    file_len_K = atol(sz_res);
    760726    log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     727    mr_free(sz_res);
     728    mr_free(command);
     729
    761730    return (file_len_K);
    762731}
     
    770739{
    771740    /*@ buffers ***************************************************** */
    772     char *fname;
    773     char *biggielist;
    774     char *comment;
    775     char *tmp;
    776     char *q;
    777     char *command;
     741    char *fname = NULL;
     742    char *biggielist = NULL;
     743    char *tmp = NULL;
     744    char *command = NULL;
    778745
    779746    /*@ long ******************************************************** */
     
    786753    /*@ end vars *************************************************** */
    787754
    788     malloc_string(fname);
    789     malloc_string(biggielist);
    790     malloc_string(comment);
    791     malloc_string(tmp);
    792     malloc_string(command);
    793755    log_it("Calculating size of all biggiefiles (in total)");
    794     sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     756    mr_asprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
    795757    log_it("biggielist = %s", biggielist);
    796     if (!(fin = fopen(biggielist, "r"))) {
    797         log_OS_error
    798             ("Cannot open biggielist. OK, so estimate is based on filesets only.");
     758    fin = fopen(biggielist, "r");
     759    mr_free(biggielist);
     760
     761    if (!(fin)) {
     762        log_OS_error("Cannot open biggielist. OK, so estimate is based on filesets only.");
    799763    } else {
    800764        log_msg(4, "Reading it...");
    801         for (q = fgets(fname, MAX_STR_LEN, fin); !feof(fin) && (q != NULL);
    802              q = fgets(fname, MAX_STR_LEN, fin)) {
     765        for (mr_getline(fname, fin); !feof(fin); mr_getline(fname, fin)) {
    803766            if (fname[strlen(fname) - 1] <= 32) {
    804767                fname[strlen(fname) - 1] = '\0';
     
    807770                if (is_dev_an_NTFS_dev(fname)) {
    808771                    if ( !find_home_of_exe("ntfsresize")) {
     772                        mr_free(tmp);
     773                        mr_free(fname);
    809774                        fatal_error("ntfsresize not found");
    810775                    }
    811                     sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
     776                    mr_free(tmp);
     777
     778                    mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    812779                    log_it("command = %s", command);
    813                     strcpy (tmp, call_program_and_get_last_line_of_output(command));
     780                    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     781                    mr_free(command);
     782
    814783                    log_it("res of it = %s", tmp);
    815784                    file_len_K = atoll(tmp) / 1024L;
     785                    mr_free(tmp);
    816786                } else {
    817787                    file_len_K = get_phys_size_of_drive(fname) * 1024L;
     
    825795                log_msg(4, "%s --> %ld K", fname, file_len_K);
    826796            }
    827             sprintf(comment,
    828                     "After adding %s, scratchL+%ld now equals %ld", fname,
    829                     file_len_K, scratchL);
    830             log_msg(4, comment);
     797            log_msg(4, "After adding %s, scratchL+%ld now equals %ld", fname, file_len_K, scratchL);
    831798            if (feof(fin)) {
    832799                break;
    833800            }
    834         }
     801            mr_free(fname);
     802        }
     803        mr_free(fname);
    835804    }
    836805    log_it("Closing...");
    837806    paranoid_fclose(fin);
    838807    log_it("Finished calculating total size of all biggiefiles");
    839     paranoid_free(fname);
    840     paranoid_free(biggielist);
    841     paranoid_free(comment);
    842     paranoid_free(tmp);
    843     paranoid_free(command);
    844808    return (scratchL);
    845809}
     
    854818{
    855819    /*@ buffer ****************************************************** */
    856     char tmp[MAX_STR_LEN];
    857     char command[MAX_STR_LEN * 2];
     820    char *tmp = NULL;
     821    char *command = NULL;
    858822    long long llres;
    859823    /*@ pointers **************************************************** */
     
    863827    /*@ end vars *************************************************** */
    864828
    865     sprintf(command, "du -sk %s", mountpt);
     829    mr_asprintf(command, "du -sk %s", mountpt);
    866830    errno = 0;
    867831    fin = popen(command, "r");
     
    870834      llres = 0;
    871835    } else {
    872       p = fgets(tmp, MAX_STR_LEN, fin);
     836      mr_getline(tmp, fin);
    873837      paranoid_pclose(fin);
    874838      p = strchr(tmp, '\t');
     
    880844        llres += (int) (*p - '0');
    881845      }
    882     }
     846      mr_free(tmp);
     847    }
     848    mr_free(command);
    883849
    884850    return (llres);
     
    928894{
    929895    /*@ buffers *** */
    930     char command[MAX_STR_LEN * 2];
    931     char errorstr[MAX_STR_LEN];
    932 
    933 
    934     sprintf(command, "which %s > /dev/null 2> /dev/null", fname);
    935     sprintf(errorstr,
    936             "Please install '%s'. I cannot find it on your system.",
    937             fname);
    938     if (system(command)) {
    939         log_to_screen(errorstr);
    940         log_to_screen
    941             ("There may be hyperlink at http://www.mondorescue.org/downloads.shtml which");
     896    char *command = NULL;
     897    int res = 0;
     898
     899    mr_asprintf(command, "which %s > /dev/null 2> /dev/null", fname);
     900    res = system(command);
     901    mr_free(command);
     902
     903    if (res) {
     904        log_to_screen("Please install '%s'. I cannot find it on your system.", fname);
     905        log_to_screen("There may be hyperlink at http://www.mondorescue.org which");
    942906        log_to_screen("will take you to the relevant (missing) package.");
    943907        return (1);
     
    10381002{
    10391003    /*@ Char buffers ** */
    1040     char command[MAX_STR_LEN * 2];
    1041     char tmp[MAX_STR_LEN];
     1004    char *command = NULL;
     1005    char *tmp = NULL;
    10421006    char old_pwd[MAX_STR_LEN];
    1043 
    1044     mvaddstr_and_log_it(g_currentY, 0,
    1045                         "Copying Mondo's core files to the scratch directory");
     1007    int res = 0;
     1008
     1009    mvaddstr_and_log_it(g_currentY, 0, "Copying Mondo's core files to the scratch directory");
    10461010
    10471011    log_msg(4, "g_mondo_home='%s'", g_mondo_home);
     
    10491013        find_and_store_mondoarchives_home(g_mondo_home);
    10501014    }
    1051     sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
    1052             bkpinfo->scratchdir);
     1015    mr_asprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, bkpinfo->scratchdir);
    10531016
    10541017    log_msg(4, "command = %s", command);
    1055     if (run_program_and_log_output(command, 1)) {
     1018    res = run_program_and_log_output(command, 1);
     1019    mr_free(command);
     1020
     1021    if (res) {
    10561022        fatal_error("Failed to copy Mondo's stuff to scratchdir");
    10571023    }
    10581024
    1059     sprintf(tmp, "%s/payload.tgz", g_mondo_home);
     1025    mr_asprintf(tmp, "%s/payload.tgz", g_mondo_home);
    10601026    if (does_file_exist(tmp)) {
    1061         log_it("Untarring payload %s to scratchdir %s", tmp,
    1062                bkpinfo->scratchdir);
     1027        log_it("Untarring payload %s to scratchdir %s", tmp, bkpinfo->scratchdir);
    10631028        if (getcwd(old_pwd, MAX_STR_LEN - 1)) {
    10641029            // FIXME
     
    10671032            // FIXME
    10681033        }
    1069         sprintf(command, "tar -zxvf %s", tmp);
    1070         if (run_program_and_log_output(command, FALSE)) {
     1034        mr_asprintf(command, "tar -zxvf %s", tmp);
     1035        res = run_program_and_log_output(command, FALSE);
     1036        if (res) {
     1037            mr_free(command);
     1038            mr_free(tmp);
    10711039            fatal_error("Failed to untar payload");
    10721040        }
     1041        mr_free(command);
    10731042        if (chdir(old_pwd)) {
    10741043            // FIXME
    10751044        }
    10761045    }
    1077 
    1078     sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
    1079             bkpinfo->scratchdir);
     1046    mr_free(tmp);
     1047
     1048    mr_asprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    10801049
    10811050    if (run_program_and_log_output(command, FALSE)) {
    10821051        fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
    10831052    }
    1084 
    1085     strcpy(tmp,
    1086           call_program_and_get_last_line_of_output("which mondorestore"));
     1053    mr_free(command);
     1054
     1055    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("which mondorestore"));
    10871056    if (!tmp[0]) {
    1088         fatal_error
    1089             ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
    1090     }
    1091     sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
    1092     if (run_program_and_log_output(command, FALSE)) {
     1057        mr_free(tmp);
     1058        fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
     1059    }
     1060
     1061    mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1062    mr_free(tmp);
     1063    res = run_program_and_log_output(command, FALSE);
     1064    if (res) {
     1065        mr_free(command);
    10931066        fatal_error("Failed to copy mondorestore to tmpdir");
    10941067    }
    1095 
    1096     sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
     1068    mr_free(command);
     1069
     1070    mr_asprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
    10971071    paranoid_system(command);
     1072    mr_free(command);
    10981073
    10991074    if (bkpinfo->postnuke_tarball[0]) {
    1100         sprintf(command, "cp -f %s %s/post-nuke.tgz",
    1101                 bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
    1102         if (run_program_and_log_output(command, FALSE)) {
     1075        mr_asprintf(command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
     1076        res = run_program_and_log_output(command, FALSE);
     1077        mr_free(command);
     1078
     1079        if (res) {
    11031080            fatal_error("Unable to copy post-nuke tarball to tmpdir");
    11041081        }
    11051082    }
    1106 
    11071083
    11081084    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     
    11251101
    11261102    /*@ buffers ******** */
    1127     char netfs_dev[MAX_STR_LEN];
    1128     char netfs_mount[MAX_STR_LEN];
    1129     char netfs_client_hwaddr[MAX_STR_LEN];
    1130     char netfs_client_ipaddr[MAX_STR_LEN];
    1131     char netfs_client_netmask[MAX_STR_LEN];
    1132     char netfs_client_broadcast[MAX_STR_LEN];
    1133     char netfs_client_defgw[MAX_STR_LEN];
    1134     char netfs_server_ipaddr[MAX_STR_LEN];
    1135     char tmp[MAX_STR_LEN];
    1136     char command[MAX_STR_LEN * 2];
     1103    char *netfs_dev = NULL;
     1104    char *netfs_client_hwaddr = NULL;
     1105    char *netfs_mount = NULL;
     1106    char *netfs_client_ipaddr = NULL;
     1107    char *netfs_client_netmask = NULL;
     1108    char *netfs_client_broadcast = NULL;
     1109    char *netfs_client_defgw = NULL;
     1110    char *netfs_server_ipaddr = NULL;
     1111    char *tmp = NULL;
     1112    char *command = NULL;
    11371113
    11381114    /*@ pointers ***** */
    11391115    char *p;
    11401116
     1117    if (! bkpinfo->netfs_mount) {
     1118        fatal_error("No netfs_mount found !");
     1119    }
     1120
    11411121    log_it("Storing Network configuration");
    1142     strcpy(tmp, bkpinfo->netfs_mount);
     1122    mr_asprintf(tmp, "%s", bkpinfo->netfs_mount);
    11431123    p = strchr(tmp, ':');
    11441124    if (!p) {
    1145         fatal_error
    1146             ("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs");
     1125        fatal_error("Network mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs");
    11471126    }
    11481127    *(p++) = '\0';
    1149     strcpy(netfs_server_ipaddr, tmp);
    1150     strcpy(netfs_mount, p);
     1128    mr_asprintf(netfs_server_ipaddr, "%s", tmp);
     1129    mr_asprintf(netfs_mount, "%s", p);
     1130    mr_free(tmp);
    11511131
    11521132    /* BERLIOS : there is a bug #67 here as it only considers the first NIC */
    1153     sprintf(command,
    1154             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    1155     strcpy(netfs_dev, call_program_and_get_last_line_of_output(command));
    1156     sprintf(command,
    1157             "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev);
    1158     strcpy(netfs_client_hwaddr, call_program_and_get_last_line_of_output(command));
    1159     sprintf(command,
    1160             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    1161     strcpy(netfs_client_ipaddr,
    1162           call_program_and_get_last_line_of_output(command));
    1163     sprintf(command,
    1164             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
    1165     strcpy(netfs_client_netmask,
    1166           call_program_and_get_last_line_of_output(command));
    1167     sprintf(command,
    1168             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
    1169     strcpy(netfs_client_broadcast,
    1170           call_program_and_get_last_line_of_output(command));
    1171     sprintf(command,
    1172             "route -n | grep '^0.0.0.0' | awk '{print $2}'");
    1173     strcpy(netfs_client_defgw,
    1174           call_program_and_get_last_line_of_output(command));
    1175     sprintf(tmp,
    1176             "netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s",
    1177             netfs_client_hwaddr, netfs_client_ipaddr, netfs_server_ipaddr, netfs_mount);
     1133    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
     1134    mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command));
     1135    mr_free(command);
     1136
     1137    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
     1138    mr_asprintf(netfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command));
     1139    mr_free(command);
     1140
     1141    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
     1142    mr_asprintf(netfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command));
     1143    mr_free(command);
     1144
     1145    mr_asprintf(command, "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
     1146    mr_asprintf(netfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command));
     1147    mr_free(command);
     1148
     1149    mr_asprintf(command, "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'");
     1150    mr_asprintf(netfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command));
     1151    mr_free(command);
     1152
     1153    mr_asprintf(command, "ifconfig %s | head -1 | awk '{print $5}'", netfs_dev);
     1154    mr_asprintf(netfs_client_hwaddr, "%s" call_program_and_get_last_line_of_output(command));
     1155    mr_free(command);
     1156
     1157    log_it("netfs_client_hwaddr=%s; netfs_client_ipaddr=%s; netfs_server_ipaddr=%s; netfs_mount=%s", netfs_client_hwaddr, netfs_client_ipaddr, netfs_server_ipaddr, netfs_mount);
    11781158    if (strlen(netfs_dev) < 2) {
    1179         fatal_error
    1180             ("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified.");
    1181     }
     1159        fatal_error("Unable to find ethN (eth0, eth1, ...) adapter via Network mount you specified.");
     1160    }
     1161
    11821162    /********
    1183     * If the Network device that found above is a bonded device,
     1163    * If the Network device found above is a bonded device,
    11841164    * we need to replace it with an ethN device or the
    11851165    * networking will not start during an Network restore.
     
    11911171    if (!strncmp(netfs_dev, "bond", 4) || !strncmp(netfs_dev, "alb", 3) || !strncmp(netfs_dev, "aft", 3)) {
    11921172        log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", netfs_dev);
    1193         sprintf(command,
    1194                 "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev);
    1195         strcpy(netfs_dev, call_program_and_get_last_line_of_output(command));
     1173        mr_asprintf(command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1",netfs_client_hwaddr,netfs_dev);
     1174        mr_asprintf(netfs_dev, "%s", call_program_and_get_last_line_of_output(command));
     1175        mr_free(command);
    11961176        log_to_screen("Replacing it with %s\n", netfs_dev);
    11971177    }
    11981178
    1199     sprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir);
     1179    mr_asprintf(tmp, "%s/NETFS-DEV", bkpinfo->tmpdir);
    12001180    write_one_liner_data_file(tmp, netfs_dev);
     1181    mr_free(netfs_dev);
     1182    mr_free(tmp);
     1183
     1184    mr_asprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir);
     1185    write_one_liner_data_file(tmp, netfs_client_hwaddr);
     1186    mr_free(netfs_client_hwaddr);
     1187    mr_free(tmp);
     1188
     1189    mr_asprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir);
     1190    write_one_liner_data_file(tmp, netfs_client_ipaddr);
     1191    mr_free(netfs_client_ipaddr);
     1192    mr_free(tmp);
     1193
     1194    mr_asprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir);
     1195    write_one_liner_data_file(tmp, netfs_client_netmask);
     1196    mr_free(netfs_client_netmask);
     1197    mr_free(tmp);
     1198
     1199    mr_asprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
     1200    write_one_liner_data_file(tmp, netfs_client_broadcast);
     1201    mr_free(netfs_client_broadcast);
     1202    mr_free(tmp);
     1203
     1204    mr_asprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir);
     1205    write_one_liner_data_file(tmp, netfs_client_defgw);
     1206    mr_free(netfs_client_defgw);
     1207    mr_free(tmp);
     1208
     1209    mr_asprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir);
     1210    write_one_liner_data_file(tmp, netfs_server_ipaddr);
     1211    mr_free(netfs_server_ipaddr);
     1212    mr_free(tmp);
     1213
     1214    mr_asprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir);
     1215    write_one_liner_data_file(tmp, bkpinfo->netfs_mount);
     1216    mr_free(tmp);
     1217
     1218    if (bkpinfo->netfs_user) {
     1219        mr_asprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir);
     1220        write_one_liner_data_file(tmp, bkpinfo->netfs_user);
     1221        mr_free(tmp);
     1222    }
     1223    mr_asprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir);
     1224    write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir);
     1225    mr_free(tmp);
     1226
     1227    mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
     1228    write_one_liner_data_file(tmp, bkpinfo->prefix);
     1229    mr_free(tmp);
    12011230
    12021231    sprintf(tmp, "%s/NETFS-PROTO", bkpinfo->tmpdir);
    12031232    write_one_liner_data_file(tmp, bkpinfo->netfs_proto);
    1204 
    1205     sprintf(tmp, "%s/NETFS-CLIENT-HWADDR", bkpinfo->tmpdir);
    1206     write_one_liner_data_file(tmp, netfs_client_hwaddr);
    1207     sprintf(tmp, "%s/NETFS-CLIENT-IPADDR", bkpinfo->tmpdir);
    1208     write_one_liner_data_file(tmp, netfs_client_ipaddr);
    1209     sprintf(tmp, "%s/NETFS-CLIENT-NETMASK", bkpinfo->tmpdir);
    1210     write_one_liner_data_file(tmp, netfs_client_netmask);
    1211     sprintf(tmp, "%s/NETFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
    1212     write_one_liner_data_file(tmp, netfs_client_broadcast);
    1213     sprintf(tmp, "%s/NETFS-CLIENT-DEFGW", bkpinfo->tmpdir);
    1214     write_one_liner_data_file(tmp, netfs_client_defgw);
    1215     sprintf(tmp, "%s/NETFS-SERVER-IPADDR", bkpinfo->tmpdir);
    1216     write_one_liner_data_file(tmp, netfs_server_ipaddr);
    1217     sprintf(tmp, "%s/NETFS-SERVER-MOUNT", bkpinfo->tmpdir);
    1218     write_one_liner_data_file(tmp, bkpinfo->netfs_mount);
    1219     if (bkpinfo->netfs_user) {
    1220         sprintf(tmp, "%s/NETFS-SERVER-USER", bkpinfo->tmpdir);
    1221         write_one_liner_data_file(tmp, bkpinfo->netfs_user);
    1222     }
    1223     sprintf(tmp, "%s/NETFS-SERVER-PATH", bkpinfo->tmpdir);
    1224     write_one_liner_data_file(tmp, bkpinfo->netfs_remote_dir);
    1225     sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
    1226     write_one_liner_data_file(tmp, bkpinfo->prefix);
     1233    mr_free(tmp);
     1234
     1235
    12271236    log_it("Finished storing Network configuration");
    12281237}
    1229 
    1230 
    1231 
    1232 
    12331238
    12341239
     
    12531258{
    12541259    /*@ buffers *************** */
    1255     char tmp[MAX_STR_LEN];
     1260    char *tmp = NULL;
    12561261    char *mds = NULL;
    12571262
     
    12651270
    12661271    log_it("Estimating number of media required...");
    1267     scratchLL =
    1268         (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size)
    1269         + (long long) (size_of_all_biggiefiles_K());
     1272    scratchLL = (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size) + (long long) (size_of_all_biggiefiles_K());
    12701273    scratchLL = (scratchLL / 1024) / bkpinfo->media_size;
    12711274    scratchLL++;
     
    12741277    } else if (bkpinfo->use_gzip) {
    12751278        scratchLL = (scratchLL * 2) / 3;
     1279    } else if (bkpinfo->use_lzma) {
     1280        scratchLL = (scratchLL * 2) / 3;
    12761281    } else {
    12771282        scratchLL = scratchLL / 2;
     
    12821287    if (scratchLL <= 1) {
    12831288        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1284         sprintf(tmp,
    1285                 "Your backup will probably occupy a single %s. Maybe two.", mds);
     1289        mr_asprintf(tmp, "Your backup will probably occupy a single %s. Maybe two.", mds);
    12861290        mr_free(mds);
    12871291    } else if (scratchLL > 4) {
    1288         sprintf(tmp,
    1289                 "Your backup will occupy one meeeeellion media! (maybe %s)",
    1290                 number_to_text((int) (scratchLL + 1)));
     1292        mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1)));
    12911293    } else {
    1292         sprintf(tmp, "Your backup will occupy approximately %s media.",
    1293                 number_to_text((int) (scratchLL + 1)));
    1294     }
    1295     if (!bkpinfo->image_devs[0] && (scratchLL < 50)) {
     1294        mr_asprintf(tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1)));
     1295    }
     1296    if (scratchLL < 50) {
    12961297        log_to_screen(tmp);
    12971298    }
    1298 }
    1299 
    1300 
    1301 /**
    1302  * Get the last suffix of @p instr.
    1303  * If @p instr was "httpd.log.gz", we would return "gz".
    1304  * @param instr The filename to get the suffix of.
    1305  * @return The suffix (without a dot), or "" if none.
    1306  * @note The returned string points to static storage that will be overwritten with each call.
    1307  */
    1308 char *sz_last_suffix(char *instr)
    1309 {
    1310     static char outstr[MAX_STR_LEN];
    1311     char *p;
    1312 
    1313     p = strrchr(instr, '.');
    1314     if (!p) {
    1315         outstr[0] = '\0';
    1316     } else {
    1317         strcpy(outstr, p);
    1318     }
    1319     return (outstr);
     1299    mr_free(tmp);
    13201300}
    13211301
     
    13291309bool is_this_file_compressed(char *filename)
    13301310{
    1331     char do_not_compress_these[MAX_STR_LEN];
    1332     char tmp[MAX_STR_LEN];
     1311    char *do_not_compress_these = NULL;
     1312    char *tmp = NULL;
    13331313    char *p;
    13341314    char *q = NULL;
     
    13391319    }
    13401320
    1341     sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     1321    mr_asprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
    13421322    if (!does_file_exist(tmp)) {
     1323        mr_free(tmp);
    13431324        return (FALSE);
    13441325    }
    13451326    /* BERLIOS: This is just plain WRONG !! */
    1346     strcpy(do_not_compress_these,last_line_of_file(tmp));
     1327    mr_asprintf(do_not_compress_these,"%s", last_line_of_file(tmp));
     1328    mr_free(tmp);
    13471329
    13481330    for (p = do_not_compress_these; p != NULL; p++) {
    1349         strcpy(tmp, p);
     1331        mr_asprintf(tmp, "%s", p);
    13501332        if (strchr(tmp, ' ')) {
    13511333            *(strchr(tmp, ' ')) = '\0';
    13521334        }
    13531335        if (!strcmp(q, tmp)) {
     1336            mr_free(tmp);
     1337            mr_free(do_not_compress_these);
    13541338            return (TRUE);
    13551339        }
     
    13571341            break;
    13581342        }
    1359     }
     1343        mr_free(tmp);
     1344    }
     1345    mr_free(do_not_compress_these);
    13601346    return (FALSE);
    13611347}
Note: See TracChangeset for help on using the changeset viewer.