Skip to content

Commit

Permalink
libnuma: cleanup node cpu mask in destructor
Browse files Browse the repository at this point in the history
Free node_cpu_mask_v2[] bitmap-pointer-array and all of the bitmaps
that it points to.

Fixes the following valgrind warnings:

  16 bytes in 1 blocks are still reachable in loss record 1 of 3
     at 0x4C28BE3: malloc (vg_replace_malloc.c:299)
     by 0x4E37E05: numa_bitmask_alloc (libnuma.c:210)
     by 0x4E3998E: numa_node_to_cpus@@libnuma_1.2 (libnuma.c:1381)
     by 0x4E3A3C9: numa_run_on_node (libnuma.c:1718)
     by 0x402DB5: test (in /home/sansharm/src/numactl/.libs/numademo)
     by 0x401672: main (in /home/sansharm/src/numactl/.libs/numademo)

  512 bytes in 1 blocks are still reachable in loss record 2 of 3
     at 0x4C2A975: calloc (vg_replace_malloc.c:711)
     by 0x4E37E24: numa_bitmask_alloc (libnuma.c:214)
     by 0x4E3998E: numa_node_to_cpus@@libnuma_1.2 (libnuma.c:1381)
     by 0x4E3A3C9: numa_run_on_node (libnuma.c:1718)
     by 0x402DB5: test (in /home/sansharm/src/numactl/.libs/numademo)
     by 0x401672: main (in /home/sansharm/src/numactl/.libs/numademo)

  8,192 bytes in 1 blocks are still reachable in loss record 3 of 3
     at 0x4C2A975: calloc (vg_replace_malloc.c:711)
     by 0x4E39974: init_node_cpu_mask_v2 (libnuma.c:1266)
     by 0x4E39974: numa_node_to_cpus@@libnuma_1.2 (libnuma.c:1361)
     by 0x4E3A3C9: numa_run_on_node (libnuma.c:1718)
     by 0x402DB5: test (in /home/sansharm/src/numactl/.libs/numademo)
     by 0x401672: main (in /home/sansharm/src/numactl/.libs/numademo)

Signed-off-by:Sanskriti Sharma <sansharm@redhat.com>
  • Loading branch information
Sanskriti Sharma authored and andikleen committed Oct 15, 2018
1 parent a7ee1fc commit 2451462
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libnuma.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ numa_init(void)
memset(&numa_no_nodes, 0, sizeof(numa_no_nodes));
}

static void cleanup_node_cpu_mask_v2();

#define FREE_AND_ZERO(x) if (x) { \
numa_bitmask_free(x); \
x = NULL; \
Expand All @@ -118,6 +120,7 @@ numa_fini(void)
FREE_AND_ZERO(numa_no_nodes_ptr);
FREE_AND_ZERO(numa_memnode_ptr);
FREE_AND_ZERO(numa_nodes_ptr);
cleanup_node_cpu_mask_v2();
}

/*
Expand Down Expand Up @@ -1248,6 +1251,20 @@ static init_node_cpu_mask_v2(void)
node_cpu_mask_v2 = calloc (nnodes, sizeof(struct bitmask *));
}

static void cleanup_node_cpu_mask_v2(void)
{
if (node_cpu_mask_v2) {
int i;
int nnodes;
nnodes = numa_max_possible_node_v2_int() + 1;
for (i = 0; i < nnodes; i++) {
FREE_AND_ZERO(node_cpu_mask_v2[i]);
}
free(node_cpu_mask_v2);
node_cpu_mask_v2 = NULL;
}
}

/* This would be better with some locking, but I don't want to make libnuma
dependent on pthreads right now. The races are relatively harmless. */
int
Expand Down

0 comments on commit 2451462

Please sign in to comment.