Changeset 2241 in MondoRescue


Ignore:
Timestamp:
Jun 29, 2009, 7:19:14 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3144@localhost: bruno | 2009-06-26 12:18:08 +0200

  • Remove mr_string.c|.h useless and in de=uplication with mr_str.c|.h
  • Solve with valgrind's help some memroy leak (harmless mostly)
  • Solve a seg fault at end, when unallocating a bkpinfo member after the strcuture disallocation !
  • after mr_strtok, memory ssociated with the token needs to be free
  • Adds a new function free_newt_stuff to free newt related allocated memory
  • Do not exit if mr_free is unsuccessful, and only warn when debug > 8
Location:
branches/2.2.9/mondo/src
Files:
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/Makefile.am

    r1930 r2241  
    2525                       libmondo-string-EXT.h libmondo-tools-EXT.h \
    2626                       libmondo-verify-EXT.h  libmondo-stream-EXT.h libmondo-cli-EXT.h \
    27                        newt-specific.h \
    28                        mr_string.c mr_string.h
     27                       newt-specific.h
  • branches/2.2.9/mondo/src/common/libmondo-archive.c

    r2230 r2241  
    541541
    542542    assert(bkpinfo != NULL);
    543     malloc_string(last_filelist_number);
    544 
    545543    mr_asprintf(&tmp,
    546544            "echo '%s' | tr -s ' ' '\n' | grep -E '^/dev/.*$' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
     
    20352033    char *tmp = NULL;
    20362034    char *bigfile_fname;
    2037     char *sz_devfile;
     2035    char *sz_devfile = NULL;
    20382036    char *ntfsprog_fifo = NULL;
    20392037    /*@ long *********************************************** */
     
    20552053
    20562054    malloc_string(bigfile_fname);
    2057     malloc_string(sz_devfile);
    20582055    estimated_total_noof_slices =
    20592056        size_of_all_biggiefiles_K() / bkpinfo->optimal_set_size + 1;
     
    21112108                        "Calling ntfsclone in background because %s is an NTFS partition",
    21122109                        bigfile_fname);
    2113                 sprintf(sz_devfile, "%s/%d.%d.000",
     2110                mr_asprintf(&sz_devfile, "%s/%d.%d.000",
    21142111                        bkpinfo->tmpdir,
    21152112                        (int) (random() % 32768),
     
    21192116                switch (pid = fork()) {
    21202117                case -1:
     2118                    mr_free(sz_devfile);
    21212119                    fatal_error("Fork failure");
    21222120                case 0:
     
    21252123                            bigfile_fname, sz_devfile);
    21262124                    res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
     2125                    /* BCO/BERLIOS Does the child need to unalocate memory as well ?
     2126                    paranoid_free(bigfile_fname);
     2127                    mr_free(sz_devfile);
     2128                    */
    21272129                    exit(res);
    21282130                    break;
     
    21312133                            "feed_into_ntfsprog() called in background --- pid=%ld",
    21322134                            (long int) (pid));
     2135                    mr_free(sz_devfile);
    21332136                }
    21342137            }
    21352138            // Otherwise, use good old 'dd' and 'bzip2'
    21362139            else {
    2137                 sz_devfile[0] = '\0';
    21382140                ntfsprog_fifo = NULL;
    21392141            }
     
    21882190    paranoid_fclose(fin);
    21892191    paranoid_free(bigfile_fname);
    2190     paranoid_free(sz_devfile);
    21912192    return (retval);
    21922193}
  • branches/2.2.9/mondo/src/common/libmondo-cli.c

    r2229 r2241  
    1313#include "my-stuff.h"
    1414#include "mr_mem.h"
    15 #include "mr_string.h"
     15#include "mr_str.h"
    1616#include "mondostructures.h"
    1717#include "libmondo-cli-EXT.h"
     
    297297            log_msg (4, "Could not get the list of mounted file systems");
    298298            paranoid_free(mounted_file_system);
     299            mr_free(token);
    299300            return (1);
    300301        }
    301         log_msg (5, "token: %s", token);
     302        if (token) {
     303            log_msg (5, "token: %s", token);
     304        }
    302305        while (token != NULL) {
    303306            log_msg (5, "token: %s", token);
     
    307310            add_mounted_fs_struct(DSFptr);
    308311            strcpy(DSFptr->device, token);
     312            mr_free(token);
    309313            if ((token = strtok(NULL, token_chars)) == NULL) {
    310314                log_msg (5, "Ran out of entries on the mounted file systems list");
    311315                paranoid_free(mounted_file_system);
     316                mr_free(token);
    312317                return (1);
    313318            }
    314319            log_msg (5, "token: %s", token);
    315320            strcpy(DSFptr->mount_point, token);
     321            mr_free(token);
    316322            token = strtok(NULL, token_chars);
    317323        }
     
    410416        log_msg (5, "Found partition: %s", token);
    411417        strcpy(partitions[i++], token);
     418        mr_free(token);
    412419    }
    413420    paranoid_free(partition_list);
     
    507514                            log_msg (4, "Can't find mount point %s in mounted file systems list", token);
    508515                            paranoid_free(tmp);
     516                            mr_free(token);
    509517                            return (1);
    510518                        }
    511519                        DSFptr->check = 1;
     520                        mr_free(token);
    512521                    }
    513522                    /********
     
    535544                                log_msg (4, "Can't find device %s in mounted file systems list", token);
    536545                                paranoid_free(tmp);
     546                                mr_free(token);
    537547                                return (1);
    538548                            }
     
    540550                        }
    541551                    }
     552                    mr_free(token);
    542553                    paranoid_free(mount_list);
    543554                } else {
     
    588599                    log_msg (4, "Can't find device %s in mounted file systems list", token);
    589600                    paranoid_free(tmp);
     601                    mr_free(token);
    590602                    return (1);
    591603                }
     
    593605                break;
    594606            }
     607            mr_free(token);
    595608        }
    596609        paranoid_free(tmp);
     
    806819                break;
    807820            }
     821            mr_free(token);
    808822        }
    809823        log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
     
    11371151                break;
    11381152            }
     1153            mr_free(token);
    11391154        }
    11401155        log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
  • branches/2.2.9/mondo/src/common/libmondo-devices.c

    r2226 r2241  
    24062406{
    24072407    /*@ buffer ***************************************************** */
    2408     char *list_drives_cmd;
     2408    char *list_drives_cmd = NULL;
    24092409    char *current_drive;
    24102410
     
    24182418    /*@ end vars *************************************************** */
    24192419
    2420     malloc_string(list_drives_cmd);
    24212420    malloc_string(current_drive);
    24222421
     
    24262425#endif
    24272426    assert(which_device != NULL);
    2428     //  sprintf (list_drives_cmd,
    2429     //       "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2");
    2430 
    2431     sprintf(list_drives_cmd,
     2427
     2428    mr_asprintf(&list_drives_cmd,
    24322429            "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s",
    24332430            where_is_root_mounted());
     
    24362433    if (!(pdrives = popen(list_drives_cmd, "r"))) {
    24372434        log_OS_error("Unable to open list of drives");
    2438         paranoid_free(list_drives_cmd);
     2435        mr_free(list_drives_cmd);
    24392436        paranoid_free(current_drive);
    24402437        return ('\0');
    24412438    }
     2439    mr_free(list_drives_cmd);
     2440
    24422441    for ((void)fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives);
    24432442         (void)fgets(current_drive, MAX_STR_LEN, pdrives)) {
     
    24602459    log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
    24612460    if (count_grubs && !count_lilos) {
     2461        paranoid_free(current_drive);
    24622462        return ('G');
    24632463    } else if (count_lilos && !count_grubs) {
     2464        paranoid_free(current_drive);
    24642465        return ('L');
    24652466    } else if (count_grubs == 1 && count_lilos == 1) {
    24662467        log_it("I'll bet you used to use LILO but switched to GRUB...");
     2468        paranoid_free(current_drive);
    24672469        return ('G');
    24682470    } else {
    24692471        // We need to look on each partition then
    2470         sprintf(list_drives_cmd,
     2472        mr_asprintf(&list_drives_cmd,
    24712473            "parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/");
    24722474        log_it("list_drives_cmd = %s", list_drives_cmd);
     
    24742476        if (!(pdrives = popen(list_drives_cmd, "r"))) {
    24752477            log_OS_error("Unable to open list of drives");
    2476             paranoid_free(list_drives_cmd);
     2478            mr_free(list_drives_cmd);
    24772479            paranoid_free(current_drive);
    24782480            return ('\0');
    24792481        }
     2482        mr_free(list_drives_cmd);
     2483
    24802484        for ((void)fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives);
    24812485            (void)fgets(current_drive, MAX_STR_LEN, pdrives)) {
     
    24972501        }
    24982502        log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
    2499         paranoid_free(list_drives_cmd);
    25002503        paranoid_free(current_drive);
    25012504        if (count_grubs && !count_lilos) {
  • branches/2.2.9/mondo/src/common/libmondo-filelist.c

    r2230 r2241  
    1717#include "libmondo-gui-EXT.h"
    1818#include "libmondo-tools-EXT.h"
    19 #include "mr_string.h"
    2019#include "mr_mem.h"
     20#include "mr_str.h"
    2121
    2222#include <time.h>
     
    13831383    if (p) {
    13841384        if (!strcmp(p, "/.") || !strcmp(p, "/..")) {
     1385            mr_free(dir);
    13851386            return (0);
    13861387        }
     
    13961397          mr_asprintf(&find_excludes,"%s -path %s -prune -o", strtmp, token);
    13971398          paranoid_free(strtmp);
    1398           paranoid_free(token);
     1399          mr_free(token);
    13991400        }
    14001401#if linux
     
    15171518    paranoid_free(new_with_spaces);
    15181519    paranoid_free(skip_these);
    1519     paranoid_free(dir);
     1520    mr_free(dir);
    15201521
    15211522    if (dip) {
  • branches/2.2.9/mondo/src/common/libmondo-raid.c

    r2211 r2241  
    1717#include "lib-common-externs.h"
    1818#include "libmondo-raid.h"
    19 #include "mr_string.h"
    2019#include "mr_mem.h"
     20#include "mr_str.h"
    2121
    2222#ifdef __FreeBSD__
     
    10371037    strcpy(raidlist->el[raidlist->entries].raid_device, strtmp);
    10381038    paranoid_free(strtmp);
    1039     paranoid_free(token);
     1039    mr_free(token);
    10401040    // skip ':' and status
    10411041    token = mr_strtok (string, delims, &lastpos);
    1042     paranoid_free(token);
     1042    mr_free(token);
    10431043    token = mr_strtok (string, delims, &lastpos);
    10441044    if (!strcmp(token, "inactive")) {
     
    10461046         raidlist->el[raidlist->entries].raid_device);
    10471047      paranoid_free(string);
    1048       paranoid_free(token);
     1048      mr_free(token);
    10491049      return 1;
    10501050    }
    1051     paranoid_free(token);
     1051    mr_free(token);
    10521052
    10531053    // get RAID level
     
    10751075      return 1;
    10761076    }
    1077     paranoid_free(token);
     1077    mr_free(token);
    10781078
    10791079    // get RAID devices (type, index, device)
     
    11201120        break;
    11211121      }
    1122       paranoid_free(token);
     1122      mr_free(token);
    11231123    }
    11241124
  • branches/2.2.9/mondo/src/common/libmondo-string.c

    r2237 r2241  
    11451145 * @note The returned string points to static storage that will be overwritten with each call.
    11461146 */
     1147/* BCO/BERLIOS change that function to allocate memory, return a pointer and modify caller to free the mem */
    11471148char *media_descriptor_string(t_bkptype type_of_bkp)
    11481149{
  • branches/2.2.9/mondo/src/common/libmondo-tools.c

    r2230 r2241  
    8383
    8484extern bool am_I_in_disaster_recovery_mode(void);
    85 
    86 /* Return a string containing the date */
    87 char *mr_date(void) {
    88 
    89         time_t tcurr;
    90 
    91         tcurr = time(NULL);
    92         return(ctime(&tcurr));
    93 }
    9485
    9586/*-----------------------------------------------------------*/
     
    14111402        paranoid_free(g_magicdev_command);
    14121403
    1413         mr_free(bkpinfo->nfs_user);
    14141404    }
    14151405
  • branches/2.2.9/mondo/src/common/newt-specific.c

    r2230 r2241  
    368368    }
    369369
     370/* Free memory allocated for newt */
     371void free_newt_stuff() {
     372
     373int i;
     374
     375for (i = 0; i < g_noof_log_lines; i++) {
     376    mr_free(err_log_lines[i]);
     377}
     378mr_free(err_log_lines);
     379}
     380
    370381
    371382
     
    405416        printf("Execution run ended; result=%d\n", signal);
    406417        printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);
    407         if (strstr(bkpinfo->tmpdir ,"mondo.tmp.") != NULL) {
    408             mr_asprintf(&command, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    409             system(command);
    410             paranoid_free(command);
    411         }
     418        if (bkpinfo->tmpdir) {
     419            log_msg(8,"tempdir is %s",bkpinfo->tmpdir);
     420            if (strstr(bkpinfo->tmpdir ,"mondo.tmp.") != NULL) {
     421                log_msg(8,"erasing tempdir");
     422                mr_asprintf(&command, "rm -Rf %s", bkpinfo->tmpdir);
     423                system(command);
     424                paranoid_free(command);
     425            }
     426        }
     427        if (bkpinfo->scratchdir) {
     428            log_msg(8,"scratchdir is %s", bkpinfo->scratchdir);
     429            if (strstr(bkpinfo->scratchdir ,"mondo.scratch.") != NULL) {
     430                log_msg(8,"erasing scratchdir");
     431                mr_asprintf(&command, "rm -Rf %s", bkpinfo->scratchdir);
     432                system(command);
     433                paranoid_free(command);
     434            }
     435        }
     436        /* Free all allocated strings in bkpinfo */
     437        mr_free(bkpinfo->nfs_user);
     438
     439        /* Then free the structure */
    412440        paranoid_free(bkpinfo);
    413441        free_libmondo_global_strings();
     442        free_newt_stuff();
    414443        exit(signal);
    415444    }
  • branches/2.2.9/mondo/src/lib/mr_mem.c

    r1196 r2241  
    2525 * *allocated variable points then to the original content
    2626 * pointed to by the caller
     27 * In case of NULL pointer it just logs it
    2728 */
    2829void mr_free_int(void **allocated, int line, const char *file) {
     
    3536        *allocated = NULL;
    3637    } else {
    37         mr_msg_int(1,line,file,"Attempt to reference NULL pointer\nExiting...");
    38         mr_exit(-1,"Attempt to reference NULL pointer");
     38        mr_msg_int(8,line,file,"Attempt to free NULL pointer");
    3939    }
    4040}
  • branches/2.2.9/mondo/src/mondoarchive/mondoarchive.c

    r2211 r2241  
    7676    tmp = get_uname_m();
    7777    log_msg(0, "running on %s architecture", tmp);
    78     free(tmp);
     78    mr_free(tmp);
    7979    log_msg(0,
    8080            "-----------------------------------------------------------");
     
    138138void distro_specific_kludges_at_end_of_mondoarchive(void)
    139139{
    140 //  char tmp[500];
    141140    log_msg(2, "Restarting magicdev if necessary");
    142141    sync();
     
    166165int main(int argc, char *argv[])
    167166{
    168     char *tmp;
     167    char *tmp = NULL;
    169168    char *tmp1 = NULL;
    170169    int res, retval;
     
    196195    retval = 0;
    197196    diffs = 0;
    198     malloc_string(tmp);
    199197    malloc_libmondo_global_strings();
    200198
     
    244242    if (argc == 4 && !strcmp(argv[1], "setfattr")) {
    245243        g_loglevel = 10;
    246 //      chdir("/tmp");
    247244        g_text_mode = TRUE;
    248245        setup_newt_stuff();
     
    254251        g_text_mode = TRUE;
    255252        setup_newt_stuff();
     253        malloc_string(tmp);
    256254        turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
    257255        printf("in=%s; out=%s\n", argv[2], tmp);
     256        paranoid_free(tmp);
    258257        finish(1);
    259258    }
     
    273272    if (argc == 4 && !strcmp(argv[1], "setfacl")) {
    274273        g_loglevel = 10;
    275 //      chdir("/tmp");
    276274        g_text_mode = TRUE;
    277275        setup_newt_stuff();
     
    283281        g_text_mode = TRUE;
    284282        setup_newt_stuff();
     283        malloc_string(tmp);
    285284        if (find_cdrw_device(tmp)) {
    286285            printf("Failed to find CDR-RW drive\n");
     
    294293            printf("CD-ROM is at %s\n", tmp);
    295294        }
     295        paranoid_free(tmp);
    296296        finish(0);
    297297    }
     
    301301        g_text_mode = TRUE;
    302302        setup_newt_stuff();
     303        malloc_string(tmp);
    303304        if (find_dvd_device(tmp, atoi(argv[2]))) {
    304305            printf("Failed to find DVD drive\n");
     
    306307            printf("DVD is at %s\n", tmp);
    307308        }
     309        paranoid_free(tmp);
    308310        finish(0);
    309311    }
     
    373375        res = verify_data();
    374376        if (res < 0) {
    375             sprintf(tmp, "%d difference%c found.", -res,
     377            mr_asprintf(&tmp, "%d difference%c found.", -res,
    376378                    (-res != 1) ? 's' : ' ');
    377379            mr_asprintf(&say_at_end, tmp);
    378380            log_to_screen(tmp);
     381            mr_free(tmp);
    379382            res = 0;
    380383        }
     
    412415        paranoid_free(say_at_end);
    413416    }
    414     sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
     417    mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
    415418    run_program_and_log_output(tmp, TRUE);
     419    mr_free(tmp);
    416420    if (bkpinfo->backup_media_type == usb) {
    417421        log_msg(1, "Unmounting USB device.");
    418         sprintf(tmp, "umount %s1", bkpinfo->media_device);
     422        mr_asprintf(&tmp, "umount %s1", bkpinfo->media_device);
    419423        run_program_and_log_output(tmp, TRUE);
     424        mr_free(tmp);
    420425    }
    421426
Note: See TracChangeset for help on using the changeset viewer.