Skip to content

memory leak in get_num_procs() #2003

Closed
Closed
@jbrandmeyer

Description

@jbrandmeyer

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():

  • sysconf(_SC_NPROCESSORS_CONF) returns 32
  • CPU_ALLOC_SIZE(32) returns 8. However, sizeof(cpu_set_t) is 128.
  • Calling sched_getaffinity(0, CPU_ALLOC_SIZE(32), <a previously allocated cpu_set_t *>) returns -1: Illegal argument. However, sched_getaffinity(0, sizeof(cpu_set_t), ) succeeds.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions