diff options
author | Thierry Vignaud <tv@mageia.org> | 2013-01-14 20:24:32 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2013-01-14 20:24:32 +0000 |
commit | cd134962064d824cb883c082d563bb7b7325827f (patch) | |
tree | 212a56caca3a5cc819869f0a648109c7c8fb3f76 /dmi.c | |
parent | a3d75c7c9d9aac00d72aef6088a9c2cd415bc213 (diff) | |
download | ldetect-cd134962064d824cb883c082d563bb7b7325827f.tar ldetect-cd134962064d824cb883c082d563bb7b7325827f.tar.gz ldetect-cd134962064d824cb883c082d563bb7b7325827f.tar.bz2 ldetect-cd134962064d824cb883c082d563bb7b7325827f.tar.xz ldetect-cd134962064d824cb883c082d563bb7b7325827f.zip |
dynamically resize memory when reaching max devices limit (mga#8320)
Diffstat (limited to 'dmi.c')
-rw-r--r-- | dmi.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -109,6 +109,7 @@ static struct criteria criteria_from_dmidecode(void) { char buf[BUF_SIZE]; struct criteria r = {0, NULL}; + size_t allocated = MAX_DEVICES; if (!(f = dmidecode_file ? fopen(dmidecode_file, "r") : popen("dmidecode", "r"))) { perror("dmidecode"); @@ -142,6 +143,10 @@ static struct criteria criteria_from_dmidecode(void) { char *s = buf + tab_level + 1; char *val = get_after_colon(s); if (val && lookup_field(category, s)) { + if (r.nb >= allocated) { + allocated = r.nb*2; + r.criteria = realloc(r.criteria, sizeof(struct criterion) * allocated); + } struct criterion *criterion = &r.criteria[r.nb++]; asprintf(&criterion->name, "%s/%s", category->cat_name, s); remove_ending_spaces(val); @@ -179,6 +184,7 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) { enum state { in_constraints, in_implies } state = in_implies; int was_a_blank_line = 1; + size_t allocated = MAX_DEVICES; r.nb = 0; f = fh_open("dmitable"); @@ -210,6 +216,10 @@ static struct dmi_entries entries_matching_criteria(struct criteria criteria) { was_a_blank_line = 0; if (valid[refine]) { + if (r.nb >= allocated) { + allocated = r.nb*2; + r.entries = realloc(r.entries, sizeof(struct criterion) * allocated); + } struct dmi_entry *entry = &r.entries[r.nb++]; s += strlen("=> "); |