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

r3145@localhost: bruno | 2009-06-29 17:18:58 +0200

  • Remove 2 memory leaks and change the behavoir for function media_descriptor_string which now allocates the string it returns (which needs to be free by the caller)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-string.c

    r2241 r2242  
    10921092    static char outstr[MAX_STR_LEN];
    10931093    char *pos_w_commas, *tmp;
     1094    char *mds = NULL;
    10941095
    10951096    assert(bkpinfo != NULL);
     
    11221123            (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 /
    11231124                   bkpinfo->media_size[g_current_media_number]);
    1124         sprintf(outstr, "%s %d: [",
    1125                 media_descriptor_string(bkpinfo->backup_media_type),
    1126                 g_current_media_number);
     1125        mds = media_descriptor_string(bkpinfo->backup_media_type);
     1126        sprintf(outstr, "%s %d: [", mds, g_current_media_number);
     1127        mr_free(mds);
    11271128    }
    11281129    for (j = 0; j < percentage; j += 5) {
     
    11461147 */
    11471148/* BCO/BERLIOS change that function to allocate memory, return a pointer and modify caller to free the mem */
    1148 char *media_descriptor_string(t_bkptype type_of_bkp)
    1149 {
    1150     static char *type_of_backup = NULL;
    1151 
    1152     if (!type_of_backup) {
    1153         malloc_string(type_of_backup);
    1154     }
     1149char *media_descriptor_string(t_bkptype type_of_bkp) {
     1150
     1151    char *type_of_backup = NULL;
    11551152
    11561153    switch (type_of_bkp) {
    11571154    case dvd:
    1158         strcpy(type_of_backup, "DVD");
     1155        mr_asprintf(&type_of_backup, "DVD");
    11591156        break;
    11601157    case cdr:
    1161         strcpy(type_of_backup, "CDR");
     1158        mr_asprintf(&type_of_backup, "CDR");
    11621159        break;
    11631160    case cdrw:
    1164         strcpy(type_of_backup, "CDRW");
     1161        mr_asprintf(&type_of_backup, "CDRW");
    11651162        break;
    11661163    case tape:
    1167         strcpy(type_of_backup, "tape");
     1164        mr_asprintf(&type_of_backup, "tape");
    11681165        break;
    11691166    case cdstream:
    1170         strcpy(type_of_backup, "CDR");
     1167        mr_asprintf(&type_of_backup, "CDR");
    11711168        break;
    11721169    case udev:
    1173         strcpy(type_of_backup, "udev");
     1170        mr_asprintf(&type_of_backup, "udev");
    11741171        break;
    11751172    case iso:
    1176         strcpy(type_of_backup, "ISO");
     1173        mr_asprintf(&type_of_backup, "ISO");
    11771174        break;
    11781175    case nfs:
    1179         strcpy(type_of_backup, "nfs");
     1176        mr_asprintf(&type_of_backup, "nfs");
    11801177        break;
    11811178    case usb:
    1182         strcpy(type_of_backup, "USB");
     1179        mr_asprintf(&type_of_backup, "USB");
    11831180        break;
    11841181    default:
    1185         strcpy(type_of_backup, "ISO");
     1182        mr_asprintf(&type_of_backup, "ISO");
    11861183    }
    11871184    return (type_of_backup);
Note: See TracChangeset for help on using the changeset viewer.