Ignore:
Timestamp:
Sep 17, 2009, 3:45:24 AM (15 years ago)
Author:
Bruno Cornec
Message:

Removes some malloc_string static allocation

File:
1 edited

Legend:

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

    r2357 r2405  
    4343
    4444  /** needs malloc *******/
    45     char *checksum_ptr = NULL;
    46     char *original_cksum_ptr = NULL;
    47     char *bigfile_fname_ptr = NULL;
    48     char *tmp_ptr = NULL;
    49     char *command_ptr = NULL;
    50 
    51     char *checksum, *bigfile_fname, *tmp, *command;
     45    char *checksum = NULL;
     46    char *original_cksum = NULL;
     47    char *bigfile_fname = NULL;
     48    char *tmp = NULL;
     49    char *command = NULL;
    5250
    5351    char *p;
     
    5654
    5755    struct s_filename_and_lstat_info biggiestruct;
    58 
    59     malloc_string(checksum);
    60     malloc_string(bigfile_fname);
    61     malloc_string(tmp);
    62     malloc_string(command);
    6356
    6457  /*********************************************************************
     
    8376    paranoid_fclose(fin);
    8477
    85     mr_asprintf(checksum_ptr, "%s", biggiestruct.checksum);
    86     mr_asprintf(bigfile_fname_ptr, "%s", biggiestruct.filename);
     78    mr_asprintf(checksum, "%s", biggiestruct.checksum);
     79    mr_asprintf(bigfile_fname, "%s", biggiestruct.filename);
    8780
    8881    log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);
     
    9083
    9184    if (!g_text_mode) {
    92         mr_asprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    93         newtDrawRootText(0, 22, tmp_ptr);
    94         paranoid_free(tmp_ptr);
     85        mr_asprintf(tmp, "Comparing %s", bigfile_fname);
     86        newtDrawRootText(0, 22, tmp);
     87        paranoid_free(tmp);
    9588        newtRefresh();
    9689    }
    9790    if (!checksum[0]) {
    98         log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr);
    99     }
    100     if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) {
    101         log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname_ptr);
    102         mr_free(bigfile_fname_ptr);
     91        log_msg(2, "Warning - %s has no checksum", bigfile_fname);
     92    }
     93    if (!strncmp(bigfile_fname, "/dev/", 5)) {
     94        log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname);
     95        mr_free(bigfile_fname);
    10396        return (1);
    10497    }
    10598
    106     mr_asprintf(command_ptr, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname_ptr);
    107     log_msg(2, command_ptr);
    108     i =  system(command_ptr);
    109     mr_free(command_ptr);
    110 
    111     mr_asprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
    112     paranoid_system(tmp_ptr);
    113     paranoid_free(tmp_ptr);
     99    mr_asprintf(command, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname);
     100    log_msg(2, command);
     101    i =  system(command);
     102    mr_free(command);
     103
     104    mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);
     105    paranoid_system(tmp);
     106    paranoid_free(tmp);
    114107
    115108    if (i) {
     
    120113            log_msg(2,
    121114                    "Unable to open /tmp/md5sum.txt; can't get live checksum");
    122             mr_free(bigfile_fname_ptr);
     115            mr_free(bigfile_fname);
    123116            return (1);
    124117        } else {
    125             mr_getline(original_cksum_ptr, fin);
     118            mr_getline(original_cksum, fin);
    126119            paranoid_fclose(fin);
    127             p = strchr(original_cksum_ptr, ' ');
     120            p = strchr(original_cksum, ' ');
    128121            if (p) {
    129122                *p = '\0';
     
    131124        }
    132125    }
    133     mr_asprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);
    134     if ((original_cksum_ptr != NULL) && (strcmp(checksum_ptr, original_cksum_ptr) == 0)) {
    135         mr_strcat(tmp_ptr, " ... OK");
    136     } else {
    137         mr_strcat(tmp_ptr, "... changed");
     126    mr_asprintf(tmp, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname);
     127    if ((original_cksum != NULL) && (strcmp(checksum, original_cksum) == 0)) {
     128        mr_strcat(tmp, " ... OK");
     129    } else {
     130        mr_strcat(tmp, "... changed");
    138131        retval++;
    139132    }
    140     mr_free(checksum_ptr);
    141     mr_free(original_cksum_ptr);
    142 
    143     log_msg(1, tmp_ptr);
    144     paranoid_free(tmp_ptr);
     133    mr_free(checksum);
     134    mr_free(original_cksum);
     135
     136    log_msg(1, tmp);
     137    paranoid_free(tmp);
    145138
    146139    if (retval) {
     
    148141            fatal_error("Cannot openout changed.txt");
    149142        }
    150         fprintf(fout, "%s\n", bigfile_fname_ptr);
     143        fprintf(fout, "%s\n", bigfile_fname);
    151144        paranoid_fclose(fout);
    152145    }
    153     mr_free(bigfile_fname_ptr);
    154 
    155     paranoid_free(bigfile_fname);
    156     paranoid_free(checksum);
    157     paranoid_free(command);
    158     paranoid_free(tmp);
     146    mr_free(bigfile_fname);
    159147
    160148    return (retval);
Note: See TracChangeset for help on using the changeset viewer.