Changeset 2099 in MondoRescue for branches/2.2.8


Ignore:
Timestamp:
Dec 23, 2008, 11:35:19 AM (15 years ago)
Author:
Bruno Cornec
Message:
  • Remove some static allocation in a recursive function which lead to mondoarchive consuming wy too much memory.
File:
1 edited

Legend:

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

    r2059 r2099  
    13641364    struct dirent *dit;
    13651365    struct stat statbuf;
    1366     char new[MAX_STR_LEN];
     1366    char *new;
    13671367    char *tmp;
    1368     char *sth_B;
    13691368    static int percentage = 0;
    1370     char *ith_B;
    13711369    char *skip_these;
    13721370    char *new_with_spaces;
     
    13861384    time_t this_time;
    13871385
    1388     malloc_string(tmp);
    1389     sth_B = malloc(8*MAX_STR_LEN);
    1390     malloc_string(ith_B);
    1391     malloc_string(new_with_spaces);
    13921386    p = strrchr(dir, '/');
    13931387    if (p) {
     
    14231417        system(strtmp);
    14241418        paranoid_free(strtmp);
    1425         sprintf(tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
     1419        asprintf(&tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    14261420        g_skeleton_entries =
    14271421            1 + atol(call_program_and_get_last_line_of_output(tmp));
     1422        paranoid_free(tmp);
    14281423        sprintf(name_of_evalcall_form, "Making catalog of %s", dir);
    14291424        open_evalcall_form(name_of_evalcall_form);
     
    14521447#ifndef _XWIN
    14531448                if (!g_text_mode) {
    1454                     sprintf(tmp, "Reading %-68s", dir);
     1449                    asprintf(&tmp, "Reading %-68s", dir);
    14551450                    newtDrawRootText(0, g_noof_rows - 3, tmp);
     1451                    paranoid_free(tmp);
    14561452                }
    14571453#endif
     
    14651461//  log_msg(0, "Cataloguing %s", dir);
    14661462    if (sth[0] == ' ') {
    1467         skip_these = sth;
     1463        asprintf(&skip_these, "%s", sth);
    14681464    } else {
    1469         skip_these = sth_B;
    1470         sprintf(skip_these, " %s ", sth);
    1471     }
    1472     sprintf(new_with_spaces, " %s ", dir);
     1465        asprintf(&skip_these, " %s ", sth);
     1466    }
     1467    asprintf(&new_with_spaces, " %s ", dir);
    14731468    if ((dip = opendir(dir)) == NULL) {
    1474         sprintf(tmp,"opendir %s", dir);
     1469        asprintf(&tmp,"opendir %s", dir);
    14751470        log_OS_error(tmp);
     1471        paranoid_free(tmp);
    14761472    } else if (strstr(skip_these, new_with_spaces)) {
    14771473        fprintf(fout, "%s\n", dir); // if excluded dir then print dir ONLY
     
    14801476        while ((dit = readdir(dip)) != NULL) {
    14811477            i++;
    1482             strcpy(new, dir);
    14831478            if (strcmp(dir, "/")) {
    1484                 strcat(new, "/");
     1479                asprintf(&new,"%s/%s",dir,dit->d_name);
     1480            } else {
     1481                asprintf(&new,"%s%s",dir,dit->d_name);
    14851482            }
    1486             strcat(new, dit->d_name);
    1487             new_with_spaces[0] = ' ';
    1488             strcpy(new_with_spaces + 1, new);
    1489             strcat(new_with_spaces, " ");
     1483            paranoid_free(new_with_spaces);
     1484            asprintf(&new_with_spaces, " %s ", new);
    14901485            if (strstr(skip_these, new_with_spaces)) {
    14911486                fprintf(fout, "%s\n", new);
     1487                paranoid_free(new_with_spaces);
    14921488            } else {
     1489                paranoid_free(new_with_spaces);
    14931490                if (!lstat(new, &statbuf)) {
    14941491                    if (!S_ISLNK(statbuf.st_mode)
     
    15041501                                counter = 0;
    15051502                                uberctr++;
    1506                                 sprintf(tmp, " %c ",
     1503                                asprintf(&tmp, " %c ",
    15071504                                        special_dot_char(uberctr));
    15081505#ifndef _XWIN
     
    15131510                                }
    15141511#endif
     1512                                paranoid_free(tmp);
    15151513                            }
    15161514                        }
     
    15181516                }
    15191517            }
    1520         }
    1521     }
     1518            paranoid_free(new);
     1519        }
     1520    }
     1521    paranoid_free(new_with_spaces);
     1522    paranoid_free(skip_these);
     1523
    15221524    if (dip) {
    15231525        if (closedir(dip) == -1) {
     
    15331535        log_msg(5, "g_skeleton_entries = %ld", g_skeleton_entries);
    15341536    }
    1535     paranoid_free(tmp);
    1536     paranoid_free(sth_B);
    1537     paranoid_free(ith_B);
    1538     paranoid_free(new_with_spaces);
    15391537    return (0);
    15401538}
     
    15871585                       char *userdef_filelist)
    15881586{
    1589     char sz_datefile_wildcard[] = MONDO_CACHE"/difflevel.%d";
    15901587    char *p, *q;
    1591     char sz_datefile[80];
     1588    char *sz_datefile;
    15921589    char *sz_filelist, *exclude_paths, *tmp;
    15931590    int i;
     
    16011598    malloc_string(command);
    16021599    malloc_string(tmp);
    1603     malloc_string(sz_filelist);
    16041600    malloc_string(g_skeleton_filelist);
    16051601    if (!(exclude_paths = malloc(8*MAX_STR_LEN))) {
    16061602        fatal_error("Cannot malloc exclude_paths");
    16071603    }
    1608     sprintf(sz_datefile, sz_datefile_wildcard, 0);
     1604    asprintf(&sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
    16091605    if (!include_paths && !userdef_filelist) {
    16101606        fatal_error
     
    16141610    sprintf(command, "mkdir -p %s/archives", scratchdir);
    16151611    paranoid_system(command);
    1616     sprintf(sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
     1612    asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
    16171613    make_hole_for_file(sz_filelist);
    16181614
     
    16401636        log_msg(2, "Differential backup. Yay.");
    16411637    }
     1638    paranoid_free(sz_datefile);
    16421639
    16431640// use user-specified filelist (if specified)
     
    17071704    sprintf(command, "mv -f %s %s", sz_filelist, tmpdir);
    17081705    paranoid_system(command);
     1706    paranoid_free(sz_filelist);
    17091707    log_msg(2, "Freeing variables");
    1710     paranoid_free(sz_filelist);
    17111708    paranoid_free(command);
    17121709    paranoid_free(exclude_paths);
Note: See TracChangeset for help on using the changeset viewer.