Possible null pointer miss on realloc
Realloc can return null pointer which will cause a crash then. Patch introduces check for controlled 'die' in case memory is not available Change-Id: I279028339b1fe756d8a511834e164e59d4cab110
This commit is contained in:
parent
c0ca39c41a
commit
26464914fe
1 changed files with 2 additions and 0 deletions
|
@ -301,6 +301,7 @@ static void read_canned_config(char* filename)
|
|||
allocated *= 2;
|
||||
canned_config = (struct fs_config_entry*)realloc(
|
||||
canned_config, allocated * sizeof(struct fs_config_entry));
|
||||
if (canned_config == NULL) die("failed to reallocate memory");
|
||||
}
|
||||
|
||||
struct fs_config_entry* cc = canned_config + used;
|
||||
|
@ -320,6 +321,7 @@ static void read_canned_config(char* filename)
|
|||
++allocated;
|
||||
canned_config = (struct fs_config_entry*)realloc(
|
||||
canned_config, allocated * sizeof(struct fs_config_entry));
|
||||
if (canned_config == NULL) die("failed to reallocate memory");
|
||||
}
|
||||
canned_config[used].name = NULL;
|
||||
|
||||
|
|
Loading…
Reference in a new issue