[PATCH 04/08] - Return freeable masks Against: numactl-2.0.3-rc2 The V2+ libnuma API provides functions to free masks [bit, cpu, node] returned by some functions. [It should probably be more specific about it being the caller's responsibility to free such masks.] However, in some cases, the library returns pointers to libnuma internal masks, such as numa_no_nodes. Instead, return pointer to freshly allocated mask that the caller can free without affecting the library's internal operation. Kornilious replaced my bogus structure assignments with calls to copy_bitmask_to_bitmask() --lts libnuma.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) Index: numactl-2.0.3-rc2/libnuma.c =================================================================== --- numactl-2.0.3-rc2.orig/libnuma.c 2009-04-27 16:49:39.000000000 -0400 +++ numactl-2.0.3-rc2/libnuma.c 2009-04-27 16:50:00.000000000 -0400 @@ -896,9 +896,9 @@ numa_get_interleave_mask_v2(void) bmp = numa_allocate_nodemask(); getpol(&oldpolicy, bmp); - if (oldpolicy == MPOL_INTERLEAVE) - return bmp; - return numa_no_nodes_ptr; + if (oldpolicy != MPOL_INTERLEAVE) + copy_bitmask_to_bitmask(numa_no_nodes_ptr, bmp); + return bmp; } __asm__(".symver numa_get_interleave_mask_v2,numa_get_interleave_mask@@libnuma_1.2"); @@ -1055,9 +1055,9 @@ numa_get_membind_v2(void) bmp = numa_allocate_nodemask(); getpol(&oldpolicy, bmp); - if (oldpolicy == MPOL_BIND) - return bmp; - return numa_all_nodes_ptr; + if (oldpolicy != MPOL_BIND) + copy_bitmask_to_bitmask(numa_all_nodes_ptr, bmp); + return bmp; } __asm__(".symver numa_get_membind_v2,numa_get_membind@@libnuma_1.2"); @@ -1629,8 +1629,10 @@ numa_parse_nodestring(char *s) mask = numa_allocate_nodemask(); - if (s[0] == 0) - return numa_no_nodes_ptr; + if (s[0] == 0){ + copy_bitmask_to_bitmask(numa_no_nodes_ptr, mask); + return mask; /* return freeable mask */ + } if (*s == '!') { invert = 1; s++; -- To unsubscribe from this list: send the line "unsubscribe linux-numa" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html