Skip to content

Commit

Permalink
shmem: handle some malloc failures
Browse files Browse the repository at this point in the history
Reported by Intel from the output of klocwork.

Signed-off-by: Brice Goglin <Brice.Goglin@inria.fr>
  • Loading branch information
bgoglin committed Jun 12, 2019
1 parent 3a9e125 commit bb6e762
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hwloc/shmem.c
@@ -1,5 +1,5 @@
/*
* Copyright © 2017-2018 Inria. All rights reserved.
* Copyright © 2017-2019 Inria. All rights reserved.
* See COPYING in top-level directory.
*/

Expand Down Expand Up @@ -214,6 +214,8 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
new->support.discovery = malloc(sizeof(*new->support.discovery));
new->support.cpubind = malloc(sizeof(*new->support.cpubind));
new->support.membind = malloc(sizeof(*new->support.membind));
if (!new->support.discovery || !new->support.cpubind || !new->support.membind)
goto out_with_support;
memcpy(new->support.discovery, old->support.discovery, sizeof(*new->support.discovery));
memcpy(new->support.cpubind, old->support.cpubind, sizeof(*new->support.cpubind));
memcpy(new->support.membind, old->support.membind, sizeof(*new->support.membind));
Expand All @@ -230,6 +232,11 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
*topologyp = new;
return 0;

out_with_support:
free(new->support.discovery);
free(new->support.cpubind);
free(new->support.membind);
free(new);
out_with_components:
hwloc_components_fini();
out_with_mmap:
Expand Down

0 comments on commit bb6e762

Please sign in to comment.