Changeset 689 in MondoRescue for trunk/mondo/mondo/common/libmondo-raid.c


Ignore:
Timestamp:
Jul 17, 2006, 7:43:58 PM (18 years ago)
Author:
bcornec
Message:

Still other memory management improvements ( I hope :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-raid.c

    r688 r689  
    403403 * @return 0 if the line was read and stored successfully, 1 if we're at end of file.
    404404 */
    405 int get_next_raidtab_line(FILE * fin, char *label, char *value)
     405int get_next_raidtab_line(FILE *fin, char *label, char *value)
    406406{
    407407    char *incoming = NULL;
    408     char *p;
     408    char *p = NULL;
    409409    size_t n = 0;
    410410
    411411    assert(fin != NULL);
    412     assert(label != NULL);
    413     assert(value != NULL);
    414 
    415     label[0] = value[0] = '\0';
     412
    416413    if (feof(fin)) {
    417414        return (1);
     
    429426            p++;
    430427        }
    431         strcpy(label, incoming);
    432         strcpy(value, p);
    433         paranoid_free(incoming);
     428        label = incoming;
     429        value = p;
    434430        return (0);
    435431    }
     
    576572                               char *fname)
    577573{
    578     FILE *fin;
    579     char *label;
    580     char *value;
     574    FILE *fin = NULL;
     575    char *label = NULL;
     576    char *value = NULL;
    581577    int items;
    582578    int v;
     
    596592    items = 0;
    597593    log_it("Loading raidtab...");
    598     malloc_string(label);
    599     malloc_string(value);
    600594    get_next_raidtab_line(fin, label, value);
    601595    while (!feof(fin)) {
     
    605599        /* find the 'raiddev' entry, indicating the start of the block of info */
    606600        while (!feof(fin) && strcmp(label, "raiddev")) {
    607             strcpy(raidlist->el[items].additional_vars.el[v].label, label);
    608             strcpy(raidlist->el[items].additional_vars.el[v].value, value);
     601            raidlist->el[items].additional_vars.el[v].label = label;
     602            raidlist->el[items].additional_vars.el[v].value = value;
    609603            v++;
    610604            get_next_raidtab_line(fin, label, value);
     
    616610        }
    617611        log_msg(2, "Record #%d (%s) found", items, value);
    618         strcpy(raidlist->el[items].raid_device, value);
     612        raidlist->el[items].raid_device = value;
    619613        for (get_next_raidtab_line(fin, label, value);
    620614             !feof(fin) && strcmp(label, "raiddev");
     
    628622    log_msg(1, "Raidtab loaded successfully.");
    629623    log_msg(1, "%d RAID devices in raidtab", items);
    630     paranoid_free(label);
    631     paranoid_free(value);
    632624    return (0);
    633625}
     
    644636 */
    645637void
    646 process_raidtab_line(FILE * fin,
     638process_raidtab_line(FILE *fin,
    647639                     struct raid_device_record *raidrec,
    648640                     char *label, char *value)
     
    650642
    651643    /*@ add mallocs * */
    652     char *tmp;
    653     char *labelB;
    654     char *valueB;
    655 
    656     struct list_of_disks *disklist;
    657     int index;
    658     int v;
    659 
    660     malloc_string(labelB);
    661     malloc_string(valueB);
     644    char *tmp = NULL;
     645    char *labelB = NULL;
     646    char *valueB = NULL;
     647
     648    struct list_of_disks *disklist = NULL;
     649    int index = 0;
     650    int v = 0;
     651
    662652    assert(fin != NULL);
    663653    assert(raidrec != NULL);
     
    716706            add_disk_to_raid_device(disklist, value, index);
    717707        }
     708        paranoid_free(labelB);
     709        paranoid_free(valueB);
    718710    } else {
    719711        v = raidrec->additional_vars.entries;
    720         strcpy(raidrec->additional_vars.el[v].label, label);
    721         strcpy(raidrec->additional_vars.el[v].value, value);
     712        raidrec->additional_vars.el[v].label = label;
     713        raidrec->additional_vars.el[v].value = value;
    722714        raidrec->additional_vars.entries = ++v;
    723715    }
    724     paranoid_free(labelB);
    725     paranoid_free(valueB);
    726716}
    727717#endif
Note: See TracChangeset for help on using the changeset viewer.