Ignore:
Timestamp:
Jan 28, 2007, 7:04:41 PM (17 years ago)
Author:
Bruno Cornec
Message:
  • Fix mindi install messages (reported by Andree Leidenfrost)
  • remove paranoid_free/free for mr_free
  • mr_asprintf used everywhere
  • mr_malloc used everywhere
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-raid.c

    r1075 r1080  
    1818#include "libmondo-raid.h"
    1919#include "mr_str.h"
     20#include "mr_mem.h"
    2021
    2122#ifdef __FreeBSD__
     
    4950    int res;
    5051
    51     command = malloc(MAX_STR_LEN * 2);
     52    command = mr_malloc(MAX_STR_LEN * 2);
    5253    strcpy(command, "grep \" /proc/mdstat");
    5354    if (raidno == -1) {
     
    5960    log_it("Is raid %d registered? Command = '%s'", raidno, command);
    6061    res = system(command);
    61     paranoid_free(command);
     62    mr_free(command);
    6263    if (res) {
    6364        return (FALSE);
     
    200201    strcpy(raidrec->additional_vars.el[lino].label, label);
    201202    strcpy(raidrec->additional_vars.el[lino].value, sz_value);
    202     paranoid_free(sz_value);
     203    mr_free(sz_value);
    203204}
    204205#endif
     
    436437    label[0] = value[0] = '\0';
    437438    if (feof(fin)) {
    438         paranoid_free(incoming);
     439        mr_free(incoming);
    439440        return (1);
    440441    }
     
    452453        strcpy(label, incoming);
    453454        strcpy(value, p);
    454         paranoid_free(incoming);
     455        mr_free(incoming);
    455456        return (0);
    456457    }
     
    480481        log_it("Raidtab is very small or non-existent. Ignoring it.");
    481482        raidlist->entries = 0;
    482         paranoid_free(tmp);
     483        mr_free(tmp);
    483484        return (0);
    484485    }
    485486    if (!(fin = fopen(fname, "r"))) {
    486487        log_it("Cannot open raidtab");
    487         paranoid_free(tmp);
     488        mr_free(tmp);
    488489        return (1);
    489490    }
     
    590591    sprintf(tmp, "%d RAID devices in raidtab", raidlist->entries);
    591592    log_it(tmp);
    592     paranoid_free(tmp);
     593    mr_free(tmp);
    593594    return (0);
    594595}
     
    616617        log_it("Raidtab is very small or non-existent. Ignoring it.");
    617618        raidlist->entries = 0;
    618         paranoid_free(tmp);
    619         paranoid_free(label);
    620         paranoid_free(value);
     619        mr_free(tmp);
     620        mr_free(label);
     621        mr_free(value);
    621622        return (0);
    622623    }
    623624    if (!(fin = fopen(fname, "r"))) {
    624625        log_it("Cannot open raidtab");
    625         paranoid_free(tmp);
    626         paranoid_free(label);
    627         paranoid_free(value);
     626        mr_free(tmp);
     627        mr_free(label);
     628        mr_free(value);
    628629        return (1);
    629630    }
     
    661662    log_msg(1, "Raidtab loaded successfully.");
    662663    log_msg(1, "%d RAID devices in raidtab", items);
    663     paranoid_free(tmp);
    664     paranoid_free(label);
    665     paranoid_free(value);
     664    mr_free(tmp);
     665    mr_free(label);
     666    mr_free(value);
    666667    return (0);
    667668}
     
    762763        raidrec->additional_vars.entries = ++v;
    763764    }
    764     paranoid_free(tmp);
    765     paranoid_free(labelB);
    766     paranoid_free(valueB);
     765    mr_free(tmp);
     766    mr_free(labelB);
     767    mr_free(valueB);
    767768}
    768769#endif
     
    820821    static char *argv[64];
    821822    char **ap;
    822     char *line = (char *) malloc(MAX_STR_LEN);
    823     if (!line)
    824         errx(1,
    825              "unable to allocate %i bytes of memory for `char *line' at %s:%i",
    826              MAX_STR_LEN, __FILE__, __LINE__);
     823    char *line = (char *) mr_malloc(MAX_STR_LEN);
    827824    (void) fgets(line, MAX_STR_LEN, f);
    828825    if (feof(f)) {
     
    868865    int i, j;
    869866    static char **ret;
    870     ret = (char **) malloc(nval * sizeof(char *));
     867    ret = (char **) mr_malloc(nval * sizeof(char *));
    871868    for (i = 0; i < (argc - nval); ++i) {
    872869        if (!strcmp(argv[i], option)) {
    873870            for (j = 0; j < nval; ++j) {
    874                 ret[j] = (char *) malloc(strlen(argv[i + j + 1]) + 1);
     871                ret[j] = (char *) mr_malloc(strlen(argv[i + j + 1]) + 1);
    875872                strcpy(ret[j], argv[i + j + 1]);
    876873            }
     
    10141011    asprintf(&strtmp, pos);
    10151012    strcpy(string, strtmp);
    1016     paranoid_free(strtmp);
     1013    mr_free(strtmp);
    10171014    // if we have newline after only spaces, this is a blank line, update
    10181015    // counters, otherwise do normal parsing
     
    10351032    asprintf(&strtmp,"%s%s", device_prefix, token);
    10361033    strcpy(raidlist->el[raidlist->entries].raid_device, strtmp);
    1037     paranoid_free(strtmp);
    1038     paranoid_free(token);
     1034    mr_free(strtmp);
     1035    mr_free(token);
    10391036    // skip ':' and status
    10401037    token = mr_strtok (string, delims, &lastpos);
    1041     paranoid_free(token);
     1038    mr_free(token);
    10421039    token = mr_strtok (string, delims, &lastpos);
    10431040    if (!strcmp(token, "inactive")) {
    10441041      log_msg(1, "RAID device '%s' inactive.\n",
    10451042         raidlist->el[raidlist->entries].raid_device);
    1046       paranoid_free(string);
    1047       paranoid_free(token);
     1043      mr_free(string);
     1044      mr_free(token);
    10481045      return 1;
    10491046    }
    1050     paranoid_free(token);
     1047    mr_free(token);
    10511048
    10521049    // get RAID level
     
    10701067    } else {
    10711068      log_msg(1, "Unknown RAID level '%s'.\n", token);
    1072       paranoid_free(string);
    1073       paranoid_free(token);
     1069      mr_free(string);
     1070      mr_free(token);
    10741071      return 1;
    10751072    }
    1076     paranoid_free(token);
     1073    mr_free(token);
    10771074
    10781075    // get RAID devices (type, index, device)
     
    10941091        asprintf(&strtmp,"%s%s", device_prefix, token);
    10951092        strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
    1096         paranoid_free(strtmp);
     1093        mr_free(strtmp);
    10971094        raidlist->el[raidlist->entries].data_disks.entries++;
    10981095        break;
     
    11011098        asprintf(&strtmp,"%s%s", device_prefix, token);
    11021099        strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
    1103         paranoid_free(strtmp);
     1100        mr_free(strtmp);
    11041101        raidlist->el[raidlist->entries].spare_disks.entries++;
    11051102        break;
     
    11081105        asprintf(&strtmp,"%s%s", device_prefix, token);
    11091106        strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
    1110         paranoid_free(strtmp);
     1107        mr_free(strtmp);
    11111108        raidlist->el[raidlist->entries].failed_disks.entries++;
    11121109        log_it("At least one failed disk found in RAID array.\n");
     
    11141111      default: // error
    11151112        log_msg(1, "Unknown device type '%c'\n", type);
    1116         paranoid_free(string);
    1117         paranoid_free(token);
     1113        mr_free(string);
     1114        mr_free(token);
    11181115        return 1;
    11191116        break;
    11201117      }
    1121       paranoid_free(token);
     1118      mr_free(token);
    11221119    }
    11231120
     
    11721169        if (pos < string) {
    11731170          log_it("String underflow!\n");
    1174           paranoid_free(string);
     1171          mr_free(string);
    11751172          return 1;
    11761173        }
     
    11971194        if (pos < string) {
    11981195          printf("ERROR: String underflow!\n");
    1199           paranoid_free(string);
     1196          mr_free(string);
    12001197          return 1;
    12011198        }
     
    12141211  fclose(fin);
    12151212  // free string
    1216   paranoid_free(string);
     1213  mr_free(string);
    12171214  // return success
    12181215  return 0;
     
    12281225    int retval = 0;
    12291226
    1230     raidlist = malloc(sizeof(struct raidlist_itself));
     1227    raidlist = mr_malloc(sizeof(struct raidlist_itself));
    12311228
    12321229    // FIXME: Prefix '/dev/' should really be dynamic!
Note: See TracChangeset for help on using the changeset viewer.