Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Memory Leak from HandleWrap::Close(function) #5733

@aschmitz

Description

@aschmitz

It appears as though passing a function to the close method of a wrapped handle will result in leaked memory. I noticed this as a regression introduced in fb3ec32 with a TCPWrap handle, but it looks like it will occur for any HandleWrap object. It does not require the function to perform any action or return anything, an empty "function(){}" will still cause the leak.

It appears as though commenting out line 133 in src/handle_wrap.cc (the MakeCallback call) will not trigger this leak, although obviously this isn't an acceptable solution.

I have a testcase at https://gist.github.com/aschmitz/5743935 that requires the heapdump npm package installed, and can identify the leak (although it requires a working ab, and therefore may have trouble on OS X). It's likely not a super-minimal testcase, as it was written to track down the TCPWrap leak. If I'm doing my heapdump parsing correctly, there is an extra reference created to a handle scope for each connection made and closed.

Note that I am able to reproduce this issue on multiple Ubuntu 13.04 machines with the chris-lea PPA, and on my Ubuntu desktop with node compiled from the latest source. I believe it also reproduces on OS X, but I didn't spend much time on it there. I also tried briefly to reproduce the issue on SmartOS and was unable to do so, but I'm not sure why.

Hopefully the information above helps track down the leak. I would be happy to provide any further information, but I haven't been able to track down the exact reason for the leak, so I'm unable to provide a patch at the moment.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions