-
Notifications
You must be signed in to change notification settings - Fork 1.6k
memory leak in get_num_procs() #2003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You are talking about memory.c here I assume ? There is similar code in init.c that - I think - does not return (too) early. |
Yes, driver/others/memory.c, from the release-0.3.0 branch, inside some feature test macros at line 226. I, for one do not have access to such a well-endowed shared memory machine to test empirically. I think you'll have to ask the glibc developers just exactly what the API is supposed to be here, since its custom to glibc. That said, once upon a time, when Mono faced this problem they did use sizeof(cpu_set_t). |
Further digging in the kernel sources: sched_getaffinity() will return EINVAL if:
For AMD Threadripper 2950X, I see the following in dmesg: [ 0.000000] smpboot: Allowing 128 CPUs, 96 hotplug CPUs Sure enough, if I build up a cpu_set_t that is 128 bits large, everything works. Maybe the bug is that _SC_NPROCESSORS_CONF is returning 32 instead of 128. |
* Fix potential memory leak in cpu enumeration with glibc An early return after a failed call to sched_getaffinity would leak the previously allocated cpu_set_t. Wrong calculation of the size argument in that call increased the likelyhood of that failure. Fixes #2003
Seen in version 0.3.5+ds-1 as packaged by the Debian project for Debian Sid, on an AMD Threadripper 2950X system.
Some of my test programs are tripping GCC's memory leak detection built into their implementation of asan. It looks like the error handling paths coming out of get_num_procs() are getting triggered, and they leak memory.
Hand-walking through get_num_procs():
Its not clear to me just by reading the manpages whether or not it is glibc in error or openblas. It certainly seems reasonable to pass CPU_ALLOC_SIZE(nprocs) instead of sizeof(cpu_set_t) as the second parameter.
That said, once ret is nonzero, get_num_procs() returns without CPU_FREE()'ing the previously CPU_ALLOC()'ed
cpusetp
, and memory is leaked.The text was updated successfully, but these errors were encountered: