Skip to content

Commit

Permalink
hwloc_linux_parse_cpumap_file: handle malloc/realloc() errors
Browse files Browse the repository at this point in the history
Refs #202.

(cherry picked from commit ffadfd2)
  • Loading branch information
bgoglin committed Aug 10, 2016
1 parent 8875d4e commit 2cc7710
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/topology-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,8 @@ hwloc_linux_parse_cpumap_file(FILE *file, hwloc_bitmap_t set)
int i;

maps = malloc(nr_maps_allocated * sizeof(*maps));
if (!maps)
return -1;

/* reset to zero first */
hwloc_bitmap_zero(set);
Expand All @@ -1660,8 +1662,13 @@ hwloc_linux_parse_cpumap_file(FILE *file, hwloc_bitmap_t set)
while (fscanf(file, "%lx,", &map) == 1) /* read one kernel cpu mask and the ending comma */
{
if (nr_maps == nr_maps_allocated) {
unsigned long *tmp = realloc(maps, 2*nr_maps_allocated * sizeof(*maps));
if (!tmp) {
free(maps);
return -1;
}
maps = tmp;
nr_maps_allocated *= 2;
maps = realloc(maps, nr_maps_allocated * sizeof(*maps));
}

if (!map && !nr_maps)
Expand Down

0 comments on commit 2cc7710

Please sign in to comment.