Changeset 688 in MondoRescue for trunk/mondo/mondo/common/libmondo-mountlist.c


Ignore:
Timestamp:
Jul 17, 2006, 3:44:46 PM (18 years ago)
Author:
bcornec
Message:

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

File:
1 edited

Legend:

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

    r507 r688  
    6060
    6161    /*@ buffers ******************************************************** */
    62     char *tmp;
    63     char *device;
     62    char *tmp = NULL;
     63    char *tmp1 = NULL;
     64    char *device = NULL;
    6465    // BERLIOS : useless ? char *mountpoint;
    6566
     
    6970
    7071    /*@ pointers ******************************************************* */
    71     char *part_table_fmt;
     72    char *part_table_fmt = NULL;
    7273
    7374    /*@ initialize ***************************************************** */
    74     flaws_str[0] = '\0';
    7575    prev_part_no = 0;
    7676    // BERLIOS: tmp[0] = '\0';
     
    8181    if (physical_drive_size < 0) {
    8282        asprintf(&tmp, " %s does not exist.", drive);
    83         strcat(flaws_str, tmp);
     83        flaws_str = tmp;
    8484    } else {
    8585        asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
     86        flaws_str = NULL;
    8687    }
    8788    log_it(tmp);
     
    108109                asprintf(&tmp, " Can only have up to 'h' in disklabel.");
    109110                log_it(tmp);
    110                 strcat(flaws_str, tmp);
     111                if (flaws_str) {
     112                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     113                } else {
     114                    asprintf(&tmp1, "%s", tmp);
     115                }
     116                paranoid_free(flaws_str);
     117                flaws_str = tmp1;
    111118                paranoid_free(tmp);
    112119                res++;
     
    124131                if (!strstr(flaws_str, tmp)) {
    125132                    log_it(tmp);
    126                     strcat(flaws_str, tmp);
     133                    if (flaws_str) {
     134                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     135                    } else {
     136                        asprintf(&tmp1, "%s", tmp);
     137                    }
     138                    paranoid_free(flaws_str);
     139                    flaws_str = tmp1;
    127140                    res++;
    128141                }
     
    134147                asprintf(&tmp, " %s is tiny!", device);
    135148                log_it(tmp);
    136                 strcat(flaws_str, tmp);
     149                if (flaws_str) {
     150                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     151                } else {
     152                    asprintf(&tmp1, "%s", tmp);
     153                }
     154                paranoid_free(flaws_str);
     155                flaws_str = tmp1;
    137156                paranoid_free(tmp);
    138157                res++;
     
    147166                asprintf(&tmp, " %s has a weird mountpoint.", device);
    148167                log_it(tmp);
    149                 strcat(flaws_str, tmp);
     168                if (flaws_str) {
     169                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     170                } else {
     171                    asprintf(&tmp1, "%s", tmp);
     172                }
     173                paranoid_free(flaws_str);
     174                flaws_str = tmp1;
    150175                paranoid_free(tmp);
    151176                res++;
     
    155180                asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    156181                log_it(tmp);
    157                 strcat(flaws_str, tmp);
     182                if (flaws_str) {
     183                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     184                } else {
     185                    asprintf(&tmp1, "%s", tmp);
     186                }
     187                paranoid_free(flaws_str);
     188                flaws_str = tmp1;
    158189                paranoid_free(tmp);
    159190                res++;
     
    179210
    180211        if (((pos >= 0) || npos) && foundsome) {
    181             sprintf(flaws_str + strlen(flaws_str),
    182                     " %s has both DD and PC-style partitions.", drive);
     212            asprintf(&tmp, " %s has both DD and PC-style partitions.", drive);
     213            if (flaws_str) {
     214                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     215            } else {
     216                asprintf(&tmp1, "%s", tmp);
     217            }
     218            paranoid_free(flaws_str);
     219            flaws_str = tmp1;
     220            paranoid_free(tmp);
    183221            return ++res;       // fatal error
    184222        }
     
    191229                    asprintf(&tmp, " Gap prior to %s.", device);
    192230                    log_it(tmp);
    193                     strcat(flaws_str, tmp);
     231                    if (flaws_str) {
     232                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     233                    } else {
     234                        asprintf(&tmp1, "%s", tmp);
     235                    }
     236                    paranoid_free(flaws_str);
     237                    flaws_str = tmp1;
    194238                    paranoid_free(tmp);
    195239                    res++;
     
    199243                             prev_part_no, curr_part_no);
    200244                    log_it(tmp);
    201                     strcat(flaws_str, tmp);
     245                    if (flaws_str) {
     246                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     247                    } else {
     248                        asprintf(&tmp1, "%s", tmp);
     249                    }
     250                    paranoid_free(flaws_str);
     251                    flaws_str = tmp1;
    202252                    paranoid_free(tmp);
    203253                    res++;
     
    211261                asprintf(&tmp, " Partition %ss4 is occupied.", drive);
    212262                log_it(tmp);
    213                 strcat(flaws_str, tmp);
     263                if (flaws_str) {
     264                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     265                } else {
     266                    asprintf(&tmp1, "%s", tmp);
     267                }
     268                paranoid_free(flaws_str);
     269                flaws_str = tmp1;
    214270                paranoid_free(tmp);
    215271                res++;
     
    227283                if (!strstr(flaws_str, tmp)) {
    228284                    log_it(tmp);
    229                     strcat(flaws_str, tmp);
     285                    if (flaws_str) {
     286                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     287                    } else {
     288                        asprintf(&tmp1, "%s", tmp);
     289                    }
     290                    paranoid_free(flaws_str);
     291                    flaws_str = tmp1;
    230292                    res++;
    231293                }
     
    237299                asprintf(&tmp, " %s is tiny!", device);
    238300                log_it(tmp);
    239                 strcat(flaws_str, tmp);
     301                if (flaws_str) {
     302                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     303                } else {
     304                    asprintf(&tmp1, "%s", tmp);
     305                }
     306                paranoid_free(flaws_str);
     307                flaws_str = tmp1;
    240308                paranoid_free(tmp);
    241309                res++;
     
    250318                asprintf(&tmp, " %s has a weird mountpoint.", device);
    251319                log_it(tmp);
    252                 strcat(flaws_str, tmp);
     320                if (flaws_str) {
     321                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     322                } else {
     323                    asprintf(&tmp1, "%s", tmp);
     324                }
     325                paranoid_free(flaws_str);
     326                flaws_str = tmp1;
    253327                paranoid_free(tmp);
    254328                res++;
     
    258332                asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    259333                log_it(tmp);
    260                 strcat(flaws_str, tmp);
     334                if (flaws_str) {
     335                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     336                } else {
     337                    asprintf(&tmp1, "%s", tmp);
     338                }
     339                paranoid_free(flaws_str);
     340                flaws_str = tmp1;
    261341                paranoid_free(tmp);
    262342                res++;
     
    278358                             " Can only have up to 'h' in disklabel.");
    279359                    log_it(tmp);
    280                     strcat(flaws_str, tmp);
     360                    if (flaws_str) {
     361                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     362                    } else {
     363                        asprintf(&tmp1, "%s", tmp);
     364                    }
     365                    paranoid_free(flaws_str);
     366                    flaws_str = tmp1;
    281367                    paranoid_free(tmp);
    282368                    res++;
     
    294380                    if (!strstr(flaws_str, tmp)) {
    295381                        log_it(tmp);
    296                         strcat(flaws_str, tmp);
     382                        if (flaws_str) {
     383                            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     384                        } else {
     385                            asprintf(&tmp1, "%s", tmp);
     386                        }
     387                        paranoid_free(flaws_str);
     388                        flaws_str = tmp1;
    297389                        res++;
    298390                    }
     
    304396                    asprintf(&tmp, " %s is tiny!", device);
    305397                    log_it(tmp);
    306                     strcat(flaws_str, tmp);
     398                    if (flaws_str) {
     399                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     400                    } else {
     401                        asprintf(&tmp1, "%s", tmp);
     402                    }
     403                    paranoid_free(flaws_str);
     404                    flaws_str = tmp1;
    307405                    paranoid_free(tmp);
    308406                    res++;
     
    317415                    asprintf(&tmp, " %s has a weird mountpoint.", device);
    318416                    log_it(tmp);
    319                     strcat(flaws_str, tmp);
     417                    if (flaws_str) {
     418                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     419                    } else {
     420                        asprintf(&tmp1, "%s", tmp);
     421                    }
     422                    paranoid_free(flaws_str);
     423                    flaws_str = tmp1;
    320424                    paranoid_free(tmp);
    321425                    res++;
     
    326430                    asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    327431                    log_it(tmp);
    328                     strcat(flaws_str, tmp);
     432                    if (flaws_str) {
     433                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     434                    } else {
     435                        asprintf(&tmp1, "%s", tmp);
     436                    }
     437                    paranoid_free(flaws_str);
     438                    flaws_str = tmp1;
    329439                    paranoid_free(tmp);
    330440                    res++;
     
    347457                 amount_allocated - physical_drive_size, drive);
    348458        log_it(tmp);
    349         strcat(flaws_str, tmp);
     459        if (flaws_str) {
     460            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     461        } else {
     462            asprintf(&tmp1, "%s", tmp);
     463        }
     464        paranoid_free(flaws_str);
     465        flaws_str = tmp1;
    350466        paranoid_free(tmp);
    351467        res++;
     
    354470                 physical_drive_size - amount_allocated, drive);
    355471        log_it(tmp);
    356         strcat(flaws_str, tmp);
     472        if (flaws_str) {
     473            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     474        } else {
     475            asprintf(&tmp1, "%s", tmp);
     476        }
     477        paranoid_free(flaws_str);
     478        flaws_str = tmp1;
    357479        paranoid_free(tmp);
    358480    }
     
    391513    assert_string_is_neither_NULL_nor_zerolength(drive);
    392514    assert(mountlist != NULL);
    393     assert(flaws_str != NULL);
    394 
    395     flaws_str[0] = '\0';
     515    flaws_str = NULL;
     516
    396517    prev_part_no = 0;
    397518    // BERLIOS : useless ? tmp[0] = '\0';
     
    402523    if (physical_drive_size < 0) {
    403524        asprintf(&tmp, " %s does not exist.", drive);
    404         strcat(flaws_str, tmp);
     525        if (flaws_str) {
     526            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     527        } else {
     528            asprintf(&tmp1, "%s", tmp);
     529        }
     530        paranoid_free(flaws_str);
     531        flaws_str = tmp1;
    405532        res++;
    406533        log_msg(1, tmp);
     
    421548        if (physical_drive_size < 0) {
    422549            asprintf(&tmp, " %s refers to non-existent hardware.", device);
    423             strcat(flaws_str, tmp);
     550            if (flaws_str) {
     551                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     552            } else {
     553                asprintf(&tmp1, "%s", tmp);
     554            }
     555            paranoid_free(flaws_str);
     556            flaws_str = tmp1;
    424557            res++;
    425558            paranoid_free(tmp);
     
    432565                asprintf(&tmp, " Gap prior to %s.", device);
    433566                log_it(tmp);
    434                 strcat(flaws_str, tmp);
     567                if (flaws_str) {
     568                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     569                } else {
     570                    asprintf(&tmp1, "%s", tmp);
     571                }
     572                paranoid_free(flaws_str);
     573                flaws_str = tmp1;
    435574                paranoid_free(tmp);
    436575                res++;
     
    440579                         prev_part_no, curr_part_no);
    441580                log_it(tmp);
    442                 strcat(flaws_str, tmp);
     581                if (flaws_str) {
     582                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     583                } else {
     584                    asprintf(&tmp1, "%s", tmp);
     585                }
     586                paranoid_free(flaws_str);
     587                flaws_str = tmp1;
    443588                paranoid_free(tmp);
    444589                res++;
     
    452597            asprintf(&tmp, " Partition %s4 is occupied.", drive);
    453598            log_it(tmp);
    454             strcat(flaws_str, tmp);
     599            if (flaws_str) {
     600                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     601            } else {
     602                asprintf(&tmp1, "%s", tmp);
     603            }
     604            paranoid_free(flaws_str);
     605            flaws_str = tmp1;
    455606            paranoid_free(tmp);
    456607            res++;
     
    470621            if (!strstr(flaws_str, tmp)) {
    471622                log_it(tmp);
    472                 strcat(flaws_str, tmp);
     623                if (flaws_str) {
     624                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     625                } else {
     626                    asprintf(&tmp1, "%s", tmp);
     627                }
     628                paranoid_free(flaws_str);
     629                flaws_str = tmp1;
    473630                res++;
    474631            }
     
    480637            asprintf(&tmp, " %s is tiny!", device);
    481638            log_it(tmp);
    482             strcat(flaws_str, tmp);
     639            if (flaws_str) {
     640                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     641            } else {
     642                asprintf(&tmp1, "%s", tmp);
     643            }
     644            paranoid_free(flaws_str);
     645            flaws_str = tmp1;
    483646            paranoid_free(tmp);
    484647            res++;
     
    492655            asprintf(&tmp, " %s has a weird mountpoint.", device);
    493656            log_it(tmp);
    494             strcat(flaws_str, tmp);
     657            if (flaws_str) {
     658                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     659            } else {
     660                asprintf(&tmp1, "%s", tmp);
     661            }
     662            paranoid_free(flaws_str);
     663            flaws_str = tmp1;
    495664            paranoid_free(tmp);
    496665            res++;
     
    500669            asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    501670            log_it(tmp);
    502             strcat(flaws_str, tmp);
     671            if (flaws_str) {
     672                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     673            } else {
     674                asprintf(&tmp1, "%s", tmp);
     675            }
     676            paranoid_free(flaws_str);
     677            flaws_str = tmp1;
    503678            paranoid_free(tmp);
    504679            res++;
     
    515690                 amount_allocated - physical_drive_size, drive);
    516691        log_it(tmp);
    517         strcat(flaws_str, tmp);
     692        if (flaws_str) {
     693            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     694        } else {
     695            asprintf(&tmp1, "%s", tmp);
     696        }
     697        paranoid_free(flaws_str);
     698        flaws_str = tmp1;
    518699        paranoid_free(tmp);
    519700        res++;
     
    522703                 physical_drive_size - amount_allocated, drive);
    523704        log_it(tmp);
    524         strcat(flaws_str, tmp);
     705        if (flaws_str) {
     706            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     707        } else {
     708            asprintf(&tmp1, "%s", tmp);
     709        }
     710        paranoid_free(flaws_str);
     711        flaws_str = tmp1;
    525712        paranoid_free(tmp);
    526713    }
     
    582769            log_it(tmp);
    583770        } else {
    584             asprintf(&tmp, " ");
    585             // BERLIOS : tmp was NOT initialized ???
     771            // This function allocates tmp
    586772            if (!evaluate_drive_within_mountlist
    587773                (mountlist, drivelist->el[i].device, tmp)) {
     
    595781    }
    596782    res += look_for_duplicate_mountpoints(mountlist, flaws_str);
    597 /*  res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see
    598  which formarts are actually _supported_ by the kernel */
    599     /* log_it(flaws_str); */
    600783    return (spread_flaws_across_three_lines
    601784            (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
     
    650833
    651834    /*@ buffetr ********************************************************* */
    652     char *curr_mountpoint;
    653     char *tmp;
     835    char *curr_mountpoint = NULL;
     836    char *tmp = NULL;
     837    char *tmp1 = NULL;
    654838
    655839    assert(mountlist != NULL);
    656840    assert(flaws_str != NULL);
     841
    657842    for (currline = 0; currline < mountlist->entries; currline++) {
    658843        asprintf(&curr_mountpoint, mountlist->el[currline].mountpoint);
     
    670855            asprintf(&tmp, " %s %s's.", number_to_text(copies),
    671856                     curr_mountpoint);
    672             strcat(flaws_str, tmp);
    673857            log_it(tmp);
     858            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     859            paranoid_free(flaws_str);
     860            flaws_str = tmp1;
    674861            paranoid_free(tmp);
    675862            res++;
    676863        }
    677864        paranoid_free(curr_mountpoint);
    678     }
    679     return (res);
    680 }
    681 
    682 
    683 /**
    684  * Look for strange formats. Does not respect /proc/filesystems.
    685  * @param mountlist The mountlist to check.
    686  * @param flaws_str The flaws string to append the results to.
    687  * @return The number of weird formats found, or 0 for success.
    688  * @bug Seems orphaned; please remove.
    689  */
    690 int
    691 look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str)
    692 {
    693 
    694     /*@ int ************************************************************* */
    695     int i = 0;
    696     int res = 0;
    697 
    698     /*@ buffers ********************************************************* */
    699     char *tmp;
    700     char *format_sz;
    701 
    702     assert(mountlist != NULL);
    703     assert(flaws_str != NULL);
    704 
    705     for (i = 0; i < mountlist->entries; i++) {
    706         asprintf(&format_sz, " %s ", mountlist->el[i].format);
    707         if (!strstr(SANE_FORMATS, format_sz)
    708             && strcmp(mountlist->el[i].mountpoint, "image") != 0) {
    709             asprintf(&tmp, " %s has unknown format.",
    710                      mountlist->el[i].device);
    711             log_it(tmp);
    712             strcat(flaws_str, tmp);
    713             paranoid_free(tmp);
    714             res++;
    715         } else if ((!strcmp(mountlist->el[i].format, "swap")
    716                     && strcmp(mountlist->el[i].mountpoint, "swap")
    717                     && strcmp(mountlist->el[i].mountpoint, "none"))
    718                    || (strcmp(mountlist->el[i].format, "swap")
    719                        && !strcmp(mountlist->el[i].mountpoint, "swap")
    720                        && !strcmp(mountlist->el[i].mountpoint, "none"))) {
    721             asprintf(&tmp, " %s is half-swap.", mountlist->el[i].device);
    722             log_it(tmp);
    723             strcat(flaws_str, tmp);
    724             paranoid_free(tmp);
    725             res++;
    726         }
    727         paranoid_free(format_sz);
    728865    }
    729866    return (res);
Note: See TracChangeset for help on using the changeset viewer.