mheily / libkqueue

kqueue(2) compatibility library
Other
237 stars 77 forks source link

clang address sanitizer reports leak #98

Closed Payne-X6 closed 2 years ago

Payne-X6 commented 3 years ago

While testing our application running on libkqueue we have found memory leak using clang -fsanitize=address.

We are using libkqueue-2.3.1 but it seems to be failing also on older versions.

For reproduce just init kqueue file descriptor. Code to reproduce:

main.c

// clang -g -O0 -Wall -fsanitize=address -fno-omit-frame-pointer -lkqueue main.c

#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/event.h>

int main(void) {
    // Init kqueue
    int fd = kqueue();
    if (fd < 0) {
        return errno;
    }
    // Close kqueue should deinit
    close(fd);
    // Should be clear
    return 0;
}
arr2036 commented 2 years ago

I've pushed some changes recently that'll ensure any pending kqueue frees are processed before the process exits, this should now be fixed... at least on Linux.