Skip to content

FD leak with mmap - fix and reproducer#2

Open
bartku wants to merge 2 commits intondparker:masterfrom
bartku:fix/fd-leak
Open

FD leak with mmap - fix and reproducer#2
bartku wants to merge 2 commits intondparker:masterfrom
bartku:fix/fd-leak

Conversation

@bartku
Copy link

@bartku bartku commented Jan 18, 2026

File descriptor leak during using of mmap for CDB creation has been observed.

Leak does not occur if CDB.make(fd, mmap=False) is used. If mmap is set to either True or None then CDB does not close the file.

Leak can be reproduced using script in tools/fd_leak.py.

Root cause
Function cdb32_mmap() uses mmap through PyObject_Call(). Returned Py_Object is passed to PyObject_GetBuffer(). Object is stored in view Py_Buffer but never released.

@andre-malo
Copy link

Thank you!

The fix looks correct and I'll incorporate it. While checking out the python code I realized this should have failed on mmap.close(). Which made me look again and I realized I'm also not closing the mmap (I'm simply destroying it). The practical effect is probably zero, but it will open up the possibility of a nice and short regression test, instead of running the fullblown fd counter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants