Changeset 3288 in MondoRescue for branches/3.2


Ignore:
Timestamp:
May 6, 2014, 10:24:12 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Improve again memory management: remove some strcat calls change function percent_media_full_comment to return a dynamically allocated string
Location:
branches/3.2/mondo/src/common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-archive.c

    r3281 r3288  
    14161416                retval += res;
    14171417                g_current_progress++;
    1418                 mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());
     1418                media_usage_comment = percent_media_full_comment();
    14191419                update_progress_form(media_usage_comment);
    14201420                mr_free(media_usage_comment);
     
    21702170        g_current_progress++;
    21712171
    2172         mr_asprintf(media_usage_comment, "%s", percent_media_full_comment());
     2172        media_usage_comment = percent_media_full_comment();
    21732173        update_progress_form(media_usage_comment);
    21742174        mr_free(media_usage_comment);
     
    28932893        mr_asprintf(curr_slice_fname_compressed, "%s", slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
    28942894
    2895         mr_asprintf(tmp, "%s", percent_media_full_comment());
     2895        tmp = percent_media_full_comment();
    28962896        update_progress_form(tmp);
    28972897        mr_free(tmp);
  • branches/3.2/mondo/src/common/libmondo-devices.c

    r3278 r3288  
    16871687    int c = 0;
    16881688    int lastpos = 0;
    1689     char VG[MAX_STR_LEN];
     1689    char *VG = NULL;
    16901690    char *tmp = NULL;
    16911691    char *command = NULL;
     
    18491849            mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    18501850            log_msg(5, "  Running: %s", command);
    1851             strcpy(VG, call_program_and_get_last_line_of_output(command));
     1851            mr_asprintf(VG, "%s", call_program_and_get_last_line_of_output(command));
    18521852            mr_free(command);
    18531853
     
    19121912            }
    19131913            mr_free(tmp);
     1914            mr_free(VG);
    19141915            continue;
    19151916        } else {
  • branches/3.2/mondo/src/common/libmondo-string.c

    r3205 r3288  
    472472 * @param value The value to replace @p token.
    473473 */
     474
     475/* TODO: consider mr_strtok */
    474476void resolve_naff_tokens(char *output, char *ip, char *value, char *token)
    475477{
     
    10201022    /*@ int *********************************************** */
    10211023    int percentage;
    1022     int j;
    10231024
    10241025    /*@ buffers ******************************************* */
    1025     static char outstr[MAX_STR_LEN];
     1026    char * outstr = NULL;
    10261027    char *pos_w_commas = NULL;
    10271028    char *mds = NULL;
     
    10341035        mr_asprintf(pos_w_commas, "%s", commarize(tmp));
    10351036        mr_free(tmp);
    1036         sprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
     1037        mr_asprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
    10371038        mr_free(pos_w_commas);
    10381039        return (outstr);
     
    10451046            percentage = 100;
    10461047        }
    1047         sprintf(outstr, "Volume %d: [", g_current_media_number);
     1048        mr_asprintf(outstr, "Volume %d: [", g_current_media_number);
    10481049    } else {
    10491050        percentage = (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size);
    10501051        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1051         sprintf(outstr, "%s %d: [", mds, g_current_media_number);
     1052        mr_asprintf(outstr, "%s %d: [", mds, g_current_media_number);
    10521053        mr_free(mds);
    10531054    }
    10541055    for (j = 0; j < percentage; j += 5) {
    1055         strcat(outstr, "*");
     1056        mr_strcat(outstr, "*");
    10561057    }
    10571058    for (; j < 100; j += 5) {
    1058         strcat(outstr, ".");
    1059     }
    1060     j = (int) strlen(outstr);
    1061     sprintf(outstr + j, "] %d%% used", percentage);
     1059        mr_strcat(outstr, ".");
     1060    }
     1061    mr_strcat(outstr, "] %d%% used", percentage);
    10621062    return (outstr);
    10631063}
     1064
    10641065
    10651066/**
Note: See TracChangeset for help on using the changeset viewer.