latchset / libverto

Offical repository for libverto, an async event loop abstraction library
MIT License
16 stars 6 forks source link

memleak in vfree #14

Closed frozencemetery closed 7 years ago

frozencemetery commented 9 years ago

Issue migrated from trac ticket # 13

component: component1 | priority: major

2015-07-15 16:53:02: @tkuthan created the issue


verto_set_allocator(resize, hierarchical) has an unducumented requirement on allocator function resize, that resize(ptr, 0) is equivalent to free(ptr).

Some POSIX.1-2008 compliant implementations of the default allocator realloc don't meet this requirement. realloc(ptr, 0) may return a unique pointer that can be successfully passed to free. This new pointer never gets freed by libverto and the memory overhead leaks.

This is not an issue for linux realloc implementation, but libverto has been bundled with MIT Kerberos. MIT Kerberos is supported on platforms like Oracle Solaris, where realloc(ptr, 0) is not equivalent to free(ptr).

See https://github.com/krb5/krb5/pull/294

frozencemetery commented 8 years ago

2016-06-30 10:27:35: @greghudson commented


Note that even under glibc, realloc(NULL, 0) allocates memory and returns non-null--that is, it behaves like malloc(0) rather than free(NULL). So using realloc(x, 0) as a synonym for free(x) only works if you are careful not to free null pointers, which is of course inconvenient.

frozencemetery commented 7 years ago

Fixed by 968d542e83619de9759ac4d8f13df30e1016b6c2