Ignore:
Timestamp:
Sep 25, 2013, 8:55:39 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Backport tons of dynamic memory management rewrite from 3.1 branch. Test is needed
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/common/libmondo-filelist.c

    r3185 r3188  
    8686
    8787    /*@ pointers ********************** */
    88     char *ptr;
     88    char *ptr = NULL;
    8989    FILE *fout;
    9090
     
    116116    mr_free(tempfile);
    117117
    118     log_it(bkpinfo->image_devs);
    119 
    120     ptr = bkpinfo->image_devs;
    121 
    122     malloc_string(dev);
    123     while (ptr && *ptr) {
    124         strcpy(dev, ptr);
    125         log_it("Examining imagedev %s", dev);
    126         for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
    127         dev[i] = '\0';
    128         if (!strlen(dev)) {
    129             continue;
    130         }
    131         fprintf(fout, "%s\n", dev);
    132         log_it("Adding '%s' to biggielist", dev);
    133         if ((ptr = strchr(ptr, ' '))) {
    134             ptr++;
     118    if (bkpinfo->image_devs) {
     119        log_it("image_devs : %s", bkpinfo->image_devs);
     120
     121        ptr = bkpinfo->image_devs;
     122
     123        while (ptr && *ptr) {
     124            mr_asprintf(dev, "%s", ptr);
     125            log_it("Examining imagedev %s", dev);
     126            for (i = 0; i < (int) strlen(dev) && dev[i] != ' '; i++);
     127            dev[i] = '\0';
     128            if (!strlen(dev)) {
     129                mr_free(dev);
     130                continue;
     131            }
     132            fprintf(fout, "%s\n", dev);
     133            log_it("Adding '%s' to biggielist", dev);
     134            if ((ptr = strchr(ptr, ' '))) {
     135                ptr++;
     136            }
     137            mr_free(dev);
    135138        }
    136139    }
     
    138141    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    139142
    140     paranoid_free(dev);
    141143    return (retval);
    142144}
     
    158160
    159161    mr_asprintf(tmp_fname, "%s/sortfile", bkpinfo->tmpdir);
    160 
    161162    mr_asprintf(command, "sort %s > %s 2>> %s", orig_fname, tmp_fname, MONDO_LOGFILE);
    162163    retval = system(command);
     
    331332
    332333    if (curr_set_no == 0) {
    333         mr_asprintf(tmp, "Only one fileset. Fine.");
     334        log_msg(1, "Only one fileset. Fine.");
    334335    } else {
    335         mr_asprintf(tmp, "Filelist divided into %ld sets", curr_set_no + 1);
    336     }
    337     log_msg(1, tmp);
    338     mr_free(tmp);
     336        log_msg(1, "Filelist divided into %ld sets", curr_set_no + 1);
     337    }
    339338    close_evalcall_form();
    340339    /* This is to work around an obscure bug in Newt; open a form, close it,
     
    342341       then update_progress_form() won't show the "time taken / time remaining"
    343342       line. The bug only crops up AFTER the call to chop_filelist(). Weird. */
    344 #ifndef _XWIN
    345343    if (!g_text_mode) {
    346344        open_progress_form("", "", "", "", 100);
     
    349347        newtPopWindow();
    350348    }
    351 #endif
    352349    return (err ? 0 : curr_set_no + 1);
    353350}
     
    410407int call_exe_and_pipe_output_to_fd(char *syscall, FILE * pout)
    411408{
    412     FILE *pattr;
    413     char *tmp;
    414     char *p;
     409    FILE *pattr = NULL;
     410    char *tmp = NULL;
    415411
    416412    pattr = popen(syscall, "r");
     
    424420        return (2);
    425421    }
    426     malloc_string(tmp);
    427     for (p = fgets(tmp, MAX_STR_LEN, pattr); !feof(pattr) && (p != NULL);
    428          p = fgets(tmp, MAX_STR_LEN, pattr)) {
     422    for (mr_getline(tmp, pattr); !feof(pattr); mr_getline(tmp, pattr)) {
    429423        fputs(tmp, pout);
    430     }
     424        mr_free(tmp);
     425    }
     426    mr_free(tmp);
    431427    paranoid_pclose(pattr);
    432     paranoid_free(tmp);
    433428    return (0);
    434429}
     
    439434                 char *auxlist_fname)
    440435{
    441     FILE *fin;
    442     FILE *pout;
     436    FILE *fin = NULL;
     437    FILE *pout = NULL;
    443438    char *pout_command = NULL;
    444     char *syscall;
    445     char *file_to_analyze;
     439    char *syscall = NULL;
     440    char *file_to_analyze = NULL;
    446441    char *strtmp = NULL;
    447442    char *tmp = NULL;
    448     char *p = NULL;
    449443    int i;
    450444
     
    462456    mr_free(pout_command);
    463457
    464     malloc_string(file_to_analyze);
    465     for (p = fgets(file_to_analyze, MAX_STR_LEN, fin); !feof(fin) && (p != NULL);
    466          p = fgets(file_to_analyze, MAX_STR_LEN, fin)) {
     458    for (mr_getline(file_to_analyze, fin); !feof(fin); mr_getline(file_to_analyze, fin)) {
    467459        i = strlen(file_to_analyze);
    468460        if (i > 0 && file_to_analyze[i - 1] < 32) {
     
    472464        tmp = mr_stresc(file_to_analyze, "'", '\\', '\'');
    473465        mr_asprintf(syscall, "%s '%s' 2>> /dev/null", syscall_sprintf, tmp);    // " MONDO_LOGFILE);
    474         paranoid_free(tmp);
     466        mr_free(tmp);
    475467        log_msg(20,"calling %s\n",syscall);
    476468        call_exe_and_pipe_output_to_fd(syscall, pout);
    477         paranoid_free(syscall);
    478     }
     469        mr_free(syscall);
     470        mr_free(file_to_analyze);
     471    }
     472    mr_free(file_to_analyze);
    479473    paranoid_fclose(fin);
    480474    paranoid_pclose(pout);
    481     paranoid_free(file_to_analyze);
    482475    return (0);
    483476}
     
    522515    char *syscall_pin = NULL;
    523516    char *syscall_pout = NULL;
    524     char *incoming;
    525     char *current_subset_file, *current_master_file;
     517    char *incoming = NULL;
     518    char *current_subset_file = NULL;
     519    char *current_master_file = NULL;
    526520    char *masklist = NULL;
    527521    int retval = 0;
    528522    int i;
    529     char *p, *q, *r;
     523    char *p, *q;
    530524    char *tmp = NULL;
    531525    FILE *pin, *pout, *faclin;
    532526
    533     log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist,
    534             original_exat_fname, executable);
     527    log_msg(1, "set_EXAT_list(%s, %s, %s)", orig_msklist, original_exat_fname, executable);
    535528    if (!orig_msklist || !orig_msklist[0]
    536529        || !does_file_exist(orig_msklist)) {
     
    552545    }
    553546    if (length_of_file(original_exat_fname) <= 0) {
    554         log_msg(1,
    555                 "original_exat_fname %s is empty or missing, so no need to set EXAT list",
    556                 original_exat_fname);
     547        log_msg(1, "original_exat_fname %s is empty or missing, so no need to set EXAT list", original_exat_fname);
    557548        return (0);
    558549    }
    559     malloc_string(incoming);
    560     malloc_string(current_subset_file);
    561     malloc_string(current_master_file);
    562550    mr_asprintf(masklist, "%s/masklist", bkpinfo->tmpdir);
    563551    mr_asprintf(command, "cp -f %s %s", orig_msklist, masklist);
     
    566554
    567555    sort_file(masklist);
    568     current_subset_file[0] = current_master_file[0] = '\0';
    569556
    570557    mr_asprintf(syscall_pout, "%s --restore - 2>> %s", executable, MONDO_LOGFILE);
     
    599586//  printf("Hi there. Starting the loop\n");
    600587
    601     r = fgets(current_subset_file, MAX_STR_LEN, faclin);
    602     r = fgets(incoming, MAX_STR_LEN, pin);
    603     while (!feof(pin) && !feof(faclin) && (r != NULL)) {
    604 //      printf("incoming = %s", incoming);
    605 
    606         strcpy(current_master_file, incoming + 8);
     588    mr_getline(current_subset_file, faclin);
     589    mr_getline(incoming, pin);
     590    while (!feof(pin) && !feof(faclin)) {
     591        mr_asprintf(current_master_file, "%s", incoming + 8);
    607592
    608593        p = current_subset_file;
     
    632617        if (i < 0) {            // read another subset file in.
    633618            log_msg(my_depth, "Reading next subset line in\n\n");
    634             r = fgets(current_subset_file, MAX_STR_LEN, faclin);
     619            mr_free(current_subset_file);
     620            mr_getline(current_subset_file, faclin);
    635621            continue;
    636622        }
     
    639625            fputs(incoming, pout);
    640626        }
    641         r = fgets(incoming, MAX_STR_LEN, pin);
     627        mr_free(incoming);
     628        mr_getline(incoming, pin);
    642629        if (!i) {
    643630            log_msg(my_depth, "Copying master %s", q);
    644631        }
    645 //      if (!i) { printf("Match --- %s\n", q); }
    646632
    647633        while (!feof(pin) && strncmp(incoming, "# file: ", 8)) {
    648634            if (!i) {
    649 
    650 //    printf("%s", incoming);
    651 
    652635                fputs(incoming, pout);
    653636            }
    654             r = fgets(incoming, MAX_STR_LEN, pin);
     637            mr_free(incoming);
     638            mr_getline(incoming, pin);
    655639        }
    656640        if (!i) {
    657             r = fgets(current_subset_file, MAX_STR_LEN, faclin);
    658         }
    659     }
    660     while (!feof(pin)) {
    661         r = fgets(incoming, MAX_STR_LEN, pin);
    662     }
     641            mr_free(current_subset_file);
     642            mr_getline(current_subset_file, faclin);
     643        }
     644        mr_free(current_master_file);
     645    }
     646    mr_free(current_subset_file);
     647    mr_free(incoming);
    663648    fclose(faclin);
    664649    pclose(pin);
    665650    pclose(pout);
    666651
    667 //  printf("OK, loop is done\n");
    668 
    669652    unlink(masklist);
    670653    mr_free(masklist);
    671654
    672     paranoid_free(current_subset_file);
    673     paranoid_free(current_master_file);
    674     paranoid_free(incoming);
    675655    return (retval);
    676656}
     
    770750    noof_chars = strlen(string_to_add) + 1; /* we include the '\0' */
    771751
    772 /* walk across tree if necessary */
     752    /* walk across tree if necessary */
    773753    node = startnode;
    774754    char_to_add = string_to_add[0];
     
    779759    }
    780760
    781 /* walk down tree if appropriate */
     761    /* walk down tree if appropriate */
    782762    if (node->down != NULL && node->ch == char_to_add) {
    783763        log_msg(7, "depth=%d char=%c --- going DOWN", depth, char_to_add);
     
    793773    }
    794774
    795 /* add here */
     775    /* add here */
    796776    if (!(newnode = (struct s_node *) malloc(sizeof(struct s_node)))) {
    797777        log_to_screen("failed to malloc");
     
    864844    /*@ buffers **************************************************** */
    865845    char *command_to_open_fname = NULL;
    866     char fname[MAX_STR_LEN];
    867     char tmp[MAX_STR_LEN];
     846    char *fname = NULL;
     847    char *tmp = NULL;
    868848    char *tmp1 = NULL;
    869849    int pos_in_fname;
     
    911891
    912892    open_evalcall_form("Loading filelist from disk");
    913     for (tmp1 = fgets(fname, MAX_STR_LEN, pin); !feof(pin);
    914          tmp1 = fgets(fname, MAX_STR_LEN, pin)) {
    915         if (((fname[strlen(fname) - 1] == 13) || (fname[strlen(fname) - 1] == 10)) && (strlen(fname) > 0)) {
     893    for (mr_getline(fname, pin); !feof(pin); mr_getline(fname, pin)) {
     894        if ((strlen(fname) > 0) && (fname[strlen(fname) - 1] == 13 || fname[strlen(fname) - 1] == 10)) {
    916895            fname[strlen(fname) - 1] = '\0';
    917896        }
    918 //      strip_spaces (fname);
    919897        if (!strlen(fname)) {
     898            mr_free(fname);
    920899            continue;
    921900        }
     
    924903                continue;
    925904            }
    926             strcpy(tmp, fname);
     905            mr_asprintf(tmp, "%s", fname);
    927906            tmp[pos_in_fname] = '\0';
    928907            if (strlen(tmp)) {
    929908                add_string_at_node(filelist, tmp);
    930909            }
     910            mr_free(tmp);
    931911        }
    932912        add_string_at_node(filelist, fname);
     913
    933914        if (!(++lino % 1111)) {
    934915            percentage = (int) (lino * 100 / lines_in_filelist);
    935916            update_evalcall_form(percentage);
    936917        }
    937     }
     918        mr_free(fname);
     919    }
     920    mr_free(fname);
     921
    938922    paranoid_pclose(pin);
    939923    close_evalcall_form();
     
    12971281
    12981282
    1299 
    1300 
    13011283/**
    13021284 * Number of entries in the skeleton filelist.
     
    13141296 * @bug Return value should be @c void.
    13151297 */
    1316 int open_and_list_dir(char *dir1, char *sth, FILE * fout,
    1317                       time_t time_of_last_full_backup)
    1318 {
     1298int open_and_list_dir(char *dir1, char *sth, FILE * fout, time_t time_of_last_full_backup) {
     1299
    13191300    const char delims[] = "|";
    13201301
     
    13231304    struct stat statbuf;
    13241305    char *new;
    1325     char *tmp;
     1306    char *tmp = NULL;
    13261307    char *dir = NULL;
    13271308    static int percentage = 0;
    1328     char *skip_these;
     1309    char *skip_these = NULL;
    13291310    char *new_with_pipe;
    13301311    char *strtmp = NULL;
    13311312    char *token = NULL;
    13321313    char *find_excludes = NULL;
    1333     static char *name_of_evalcall_form;
     1314    char *name_of_evalcall_form = NULL;
     1315    char *find_skeleton_marker = NULL;
    13341316    int i;
    13351317    int lastpos = 0;
     
    13381320    static int counter = 0;
    13391321    static int uberctr = 0;
    1340     static char *find_skeleton_marker;
    1341     static long skeleton_lino = 0;
    1342     static time_t last_time = 0;
     1322    static long skeleton_lino = 0L;
     1323    static time_t last_time = (time_t)0;
    13431324    time_t this_time;
    13441325
     
    13551336
    13561337    if (!depth) {
    1357         malloc_string(name_of_evalcall_form);
    1358         malloc_string(find_skeleton_marker);
    13591338        while((token = mr_strtok(sth, delims, &lastpos)) != NULL) {
    13601339          mr_strcat(find_excludes," -path %s -prune -o", token);
     
    13751354        mr_asprintf(strtmp, "find '%s' -maxdepth %d -fstype mvfs -prune -o -path /proc -prune -o %s -type d -print > %s 2> /dev/null", dir, MAX_SKEL_DEPTH, find_excludes, g_skeleton_filelist);
    13761355#endif
    1377         paranoid_free(find_excludes);
     1356        mr_free(find_excludes);
     1357
    13781358        log_msg(5, "find command = %s", strtmp);
    13791359        paranoid_system(strtmp);
    1380         paranoid_free(strtmp);
     1360        mr_free(strtmp);
     1361
    13811362        mr_asprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    1382         g_skeleton_entries =
    1383             1 + atol(call_program_and_get_last_line_of_output(tmp));
    1384         paranoid_free(tmp);
    1385         sprintf(name_of_evalcall_form, "Making catalog of %s", dir1);
     1363        g_skeleton_entries = 1 + atol(call_program_and_get_last_line_of_output(tmp));
     1364        mr_free(tmp);
     1365
     1366        mr_asprintf(name_of_evalcall_form, "Making catalog of %s", dir1);
    13861367        open_evalcall_form(name_of_evalcall_form);
    1387         find_skeleton_marker[0] = '\0';
     1368        mr_free(name_of_evalcall_form);
     1369
    13881370        skeleton_lino = 1;
    13891371        log_msg(5, "entries = %ld", g_skeleton_entries);
     
    13911373    } else if (depth <= MAX_SKEL_DEPTH) // update evalcall form if appropriate
    13921374    {
    1393         sprintf(find_skeleton_marker,
    1394                 "grep -Fv '%s' %s > %s.new 2> /dev/null", dir,
    1395                 g_skeleton_filelist, g_skeleton_filelist);
    1396 //    log_msg(0, "fsm = %s", find_skeleton_marker);
     1375        mr_asprintf(find_skeleton_marker, "grep -Fv '%s' %s > %s.new 2> /dev/null", dir, g_skeleton_filelist, g_skeleton_filelist);
    13971376        if (!system(find_skeleton_marker)) {
    13981377            percentage = (int) (skeleton_lino * 100 / g_skeleton_entries);
    13991378            skeleton_lino++;
    1400 //        log_msg(5, "Found %s", dir);
    1401 //        log_msg(2, "Incrementing skeleton_lino; now %ld/%ld (%d%%)", skeleton_lino, g_skeleton_entries, percentage);
    1402             sprintf(find_skeleton_marker, "mv -f %s.new %s",
    1403                     g_skeleton_filelist, g_skeleton_filelist);
    1404 //        log_msg(6, "fsm = %s", find_skeleton_marker);
     1379            mr_free(find_skeleton_marker);
     1380
     1381            mr_asprintf(find_skeleton_marker, "mv -f %s.new %s", g_skeleton_filelist, g_skeleton_filelist);
    14051382            paranoid_system(find_skeleton_marker);
    14061383            time(&this_time);
    14071384            if (this_time != last_time) {
    14081385                last_time = this_time;
    1409 #ifndef _XWIN
    14101386                if (!g_text_mode) {
    14111387                    int cols, rows;
     
    14151391                    mr_free(tmp);
    14161392                }
    1417 #endif
    14181393                update_evalcall_form(percentage);
    14191394            }
    14201395        }
     1396        mr_free(find_skeleton_marker);
    14211397    }
    14221398
     
    14301406        mr_asprintf(tmp,"opendir %s", dir1);
    14311407        log_OS_error(tmp);
    1432         paranoid_free(tmp);
     1408        mr_free(tmp);
    14331409    } else if (strstr(skip_these, new_with_pipe)) {
    14341410        log_msg(10, "Found dir ***%s**** excluded", dir1);
     
    14441420                mr_asprintf(new,"%s%s",dir1,dit->d_name);
    14451421            }
    1446             paranoid_free(new_with_pipe);
     1422            mr_free(new_with_pipe);
    14471423            mr_asprintf(new_with_pipe, "|%s|", new);
    14481424            if (strstr(skip_these, new_with_pipe)) {
    14491425                fprintf(fout, "%s\n", new);
    14501426                log_msg(10, "Found child dir ***%s**** excluded", new);
    1451                 paranoid_free(new_with_pipe);
     1427                mr_free(new_with_pipe);
    14521428            } else {
    1453                 paranoid_free(new_with_pipe);
     1429                mr_free(new_with_pipe);
    14541430                if (!lstat(new, &statbuf)) {
    14551431                    if (!S_ISLNK(statbuf.st_mode)
    14561432                        && S_ISDIR(statbuf.st_mode)) {
    14571433                        log_msg(10, "Found child dir ***%s**** parsed", new);
    1458                         open_and_list_dir(new, skip_these, fout,
    1459                                           time_of_last_full_backup);
     1434                        open_and_list_dir(new, skip_these, fout, time_of_last_full_backup);
    14601435                    } else {
    1461                         if (time_of_last_full_backup == 0
    1462                             || time_of_last_full_backup <
    1463                             statbuf.st_ctime) {
     1436                        if (time_of_last_full_backup == 0 || time_of_last_full_backup < statbuf.st_ctime) {
    14641437                            log_msg(10, "Found child file ***%s**** parsed", new);
    14651438                            fprintf(fout, "%s\n", new);
     
    14681441                                uberctr++;
    14691442                                mr_asprintf(tmp, " %c ", special_dot_char(uberctr));
    1470 #ifndef _XWIN
    14711443                                if (!g_text_mode) {
    1472                                     newtDrawRootText(77, g_noof_rows - 3,
    1473                                                      tmp);
     1444                                    newtDrawRootText(77, g_noof_rows - 3, tmp);
    14741445                                    newtRefresh();
    14751446                                }
    1476 #endif
    1477                                 paranoid_free(tmp);
     1447                                mr_free(tmp);
    14781448                            }
    14791449                        }
     
    14811451                }
    14821452            }
    1483             paranoid_free(new);
    1484         }
    1485     }
    1486     paranoid_free(new_with_pipe);
    1487     paranoid_free(skip_these);
     1453            mr_free(new);
     1454        }
     1455    }
     1456    mr_free(new_with_pipe);
     1457    mr_free(skip_these);
    14881458    mr_free(dir);
    14891459
     
    14961466    if (!depth) {
    14971467        close_evalcall_form();
    1498         paranoid_free(name_of_evalcall_form);
    1499         paranoid_free(find_skeleton_marker);
    15001468        unlink(g_skeleton_filelist);
    15011469        log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
     
    15251493    char *p, *q;
    15261494    char *sz_datefile;
    1527     char *sz_filelist, *tmp;
     1495    char *sz_filelist;
    15281496    char *exclude_paths = NULL;
    15291497    FILE *fout;
     
    15341502    char *tmp2 = NULL;
    15351503
    1536     malloc_string(tmp);
    1537     malloc_string(g_skeleton_filelist);
    15381504    mr_asprintf(sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
    15391505    if (!include_paths && !userdef_filelist) {
    1540         fatal_error
    1541             ("Please supply either include_paths or userdef_filelist");
    1542     }
    1543 // make hole for filelist
     1506        fatal_error("Please supply either include_paths or userdef_filelist");
     1507    }
     1508    // make hole for filelist
    15441509    mr_asprintf(command, "mkdir -p %s/archives", scratchdir);
    15451510    paranoid_system(command);
     
    15571522        // backup last known good datefile just in case :)
    15581523        if (does_file_exist(sz_datefile)) {
    1559             mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile,
    1560                     sz_datefile);
     1524            mr_asprintf(command, "mv -f %s %s.aborted", sz_datefile, sz_datefile);
    15611525            paranoid_system(command);
    15621526            mr_free(command);
     
    15671531                                  ("date +%s"));
    15681532    } else if (lstat(sz_datefile, &statbuf)) {
    1569         log_msg(2,
    1570                 "Warning - unable to find date of previous backup. Full backup instead.");
     1533        log_msg(2, "Warning - unable to find date of previous backup. Full backup instead.");
    15711534        differential = 0;
    15721535        time_of_last_full_backup = 0;
     
    15791542// use user-specified filelist (if specified)
    15801543    if (userdef_filelist) {
    1581         log_msg(1,
    1582                 "Using the user-specified filelist - %s - instead of calculating one",
    1583                 userdef_filelist);
     1544        log_msg(1, "Using the user-specified filelist - %s - instead of calculating one", userdef_filelist);
    15841545        mr_asprintf(command, "cp -f %s %s", userdef_filelist, sz_filelist);
    15851546        if (run_program_and_log_output(command, 3)) {
     
    15891550        mr_free(command);
    15901551    } else {
    1591         log_msg(2, "include_paths = '%s'", include_paths);
     1552        if (include_paths) {
     1553            log_msg(2, "include_paths = '%s'", include_paths);
     1554        }
    15921555        log_msg(1, "Calculating filelist");
    15931556        mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
     
    15971560            log_msg(2, "Found windows FS: %s",tmp2);
    15981561            mr_asprintf(tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
    1599             paranoid_free(tmp2);
     1562            mr_free(tmp2);
    16001563            mr_asprintf(tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
    16011564            log_msg(2, "Found windows files: %s",tmp2);
    16021565        }
    1603         paranoid_free(tmp1);
     1566        mr_free(tmp1);
    16041567
    16051568        mr_asprintf(exclude_paths, MONDO_CACHE"|%s|%s|%s|.|..|"MNT_CDROM"|"MNT_FLOPPY"|/media|/tmp|/proc|/sys|/run|/dev/shm|"MINDI_CACHE, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     
    16071570            mr_strcat(exclude_paths,"|%s",excp);
    16081571        }
    1609         paranoid_free(tmp2);
     1572        mr_free(tmp2);
    16101573
    16111574        log_msg(2, "Excluding paths = '%s'", exclude_paths);
    1612         log_msg(2,
    1613                 "Generating skeleton filelist so that we can track our progress");
    1614         sprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
     1575        log_msg(2, "Generating skeleton filelist so that we can track our progress");
     1576        mr_asprintf(g_skeleton_filelist, "%s/tmpfs/skeleton.txt", tmpdir);
    16151577        make_hole_for_file(g_skeleton_filelist);
     1578
    16161579        log_msg(4, "g_skeleton_entries = %ld", g_skeleton_entries);
    16171580        log_msg(2, "Opening out filelist to %s", sz_filelist);
     
    16191582            fatal_error("Cannot openout to sz_filelist");
    16201583        }
    1621         if (strlen(include_paths) == 0) {
     1584        if ((include_paths != NULL) && (strlen(include_paths) == 0)) {
    16221585            log_msg(1, "Including only '/' in %s", sz_filelist);
    16231586            open_and_list_dir("/", exclude_paths, fout,
     
    16371600            }
    16381601        }
     1602        mr_free(exclude_paths);
    16391603        paranoid_fclose(fout);
    16401604    }
     
    16541618    paranoid_free(sz_filelist);
    16551619    log_msg(2, "Freeing variables");
    1656     paranoid_free(exclude_paths);
    1657     paranoid_free(tmp);
    1658     paranoid_free(g_skeleton_filelist);
     1620    mr_free(g_skeleton_filelist);
    16591621    log_msg(2, "Exiting");
    16601622    return (0);
    16611623}
     1624
    16621625
    16631626/**
     
    16801643
    16811644    assert(bkpinfo != NULL);
    1682     log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir,
    1683            bkpinfo->scratchdir);
     1645    log_it("tmpdir=%s; scratchdir=%s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    16841646    if (bkpinfo->make_filelist) {
    16851647        mvaddstr_and_log_it(g_currentY, 0,
     
    17921754    FILE *fin;
    17931755    FILE *fout;
    1794     char *fname;
    1795     char *tmp;
    1796     size_t len = 0;             // Scrub's patch doesn't work without that
    1797 
    1798 //  log_msg(1, "use_star = %s", (use_star)?"TRUE":"FALSE");
    1799     malloc_string(fname);
    1800     malloc_string(tmp);
     1756    char *fname = NULL;
     1757    char *tmp = NULL;
     1758
    18011759    log_msg(5, "starting");
    18021760    log_msg(5, "needles_list_fname = %s", needles_list_fname);
     
    18091767    }
    18101768    while (!feof(fin)) {
    1811 //      fscanf(fin, "%s\n", fname);
    1812         len = MAX_STR_LEN - 1;
    1813         if (getline(&fname, &len, fin)) {
    1814             // FIXME
    1815         }
     1769        mr_getline(fname, fin);
    18161770        if (!use_star) {
    18171771            if (fname[0] == '/') {
    1818                 strcpy(tmp, fname);
     1772                mr_asprintf(tmp, "%s", fname);
    18191773            } else {
    1820                 tmp[0] = '/';
    1821                 strcpy(tmp + 1, fname);
     1774                mr_asprintf(tmp, "/%s", fname);
    18221775            }
    1823             strcpy(fname, tmp);
     1776            mr_free(fname);
     1777            fname = tmp;
    18241778        }
    18251779        while (strlen(fname) > 0 && fname[strlen(fname) - 1] < 32) {
     
    18321786            if (found_node->selected) {
    18331787                if (fname[0] == '/') {
    1834                     strcpy(tmp, fname + 1);
    1835                     strcpy(fname, tmp);
     1788                    mr_asprintf(tmp, "%s", fname + 1);
     1789                    mr_free(fname);
     1790                    fname = tmp;
    18361791                }
    18371792                log_msg(5, "Found '%s'", fname);
    1838                 turn_wildcard_chars_into_literal_chars(tmp, fname);
    1839                 fprintf(fout, "%s\n", tmp);
     1793                tmp = mr_stresc(fname, "[]*?", '\\', "'");
     1794                mr_free(fname);
     1795                fname = tmp;
     1796                fprintf(fout, "%s\n", fname);
    18401797                retval++;
    18411798            }
    18421799        }
     1800        mr_free(fname);
    18431801    }
    18441802    paranoid_fclose(fout);
    18451803    paranoid_fclose(fin);
    1846     paranoid_free(fname);
    1847     paranoid_free(tmp);
    18481804    return (retval);
    18491805}
    1850 
    1851 
    1852 
    18531806
    18541807
     
    18651818                                  char *list_of_files_fname, bool flag_em)
    18661819{
    1867     FILE *fin;
    1868     char *tmp;
    1869     char *p;
    1870     struct s_node *nod;
    1871 
    1872     malloc_string(tmp);
     1820    FILE *fin = NULL;
     1821    char *tmp = NULL;
     1822    struct s_node *nod = NULL;
     1823
    18731824    log_msg(3, "Adding %s to filelist", list_of_files_fname);
    18741825    if (!(fin = fopen(list_of_files_fname, "r"))) {
     
    18761827        return (1);
    18771828    }
    1878     for (p = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (p != NULL);
    1879          p = fgets(tmp, MAX_STR_LEN, fin)) {
     1829    for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
    18801830        if (!tmp[0]) {
     1831            mr_free(tmp);
    18811832            continue;
    18821833        }
    1883         if ((tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)
    1884             && strlen(tmp) > 0) {
     1834        if ((strlen(tmp) > 0) && (tmp[strlen(tmp) - 1] == 13 || tmp[strlen(tmp) - 1] == 10)) {
    18851835            tmp[strlen(tmp) - 1] = '\0';
    18861836        }
    18871837        log_msg(2, "tmp = '%s'", tmp);
    18881838        if (!tmp[0]) {
     1839            mr_free(tmp);
    18891840            continue;
    18901841        }
     
    19001851            log_msg(5, "Flagged '%s'", tmp);
    19011852        }
    1902     }
     1853        mr_free(tmp);
     1854    }
     1855    mr_free(tmp);
    19031856    paranoid_fclose(fin);
    1904     paranoid_free(tmp);
    19051857    return (0);
    19061858}
Note: See TracChangeset for help on using the changeset viewer.