eduardbme / node-memwatch

A NodeJS library to keep an eye on your memory usage, and discover and isolate leaks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resource leak in memwatch.cc

Fotiman opened this issue · comments

The Coverity Security Scan software reports a resource leak on line 238. The actual message states:

leaked_storage: Variable baton going out of scope leaks the storage it points to.

image

However, if I understand this code correctly, here’s what I think happens:

  1. Line 222 creates a pointer to a new Baton.
  2. Line 230 stores a void pointer in the req.data property of the new Baton (which happens to be a pointer to itself)
  3. Line 237 passes the reference to the new Baton’s req property to uv_queue_work.
  4. After the noop_work_func completes, the AsyncMemwatchAfter callback will execute.
  5. That method is passed the pointer to the req property of the new Baton. It then dereferences the data property (the pointer to the original new Baton) and assigns it to a new Baton pointer. This is now pointing at the address of the originally created new Baton from line 222
  6. At the end of that function it deletes the value that was being pointed to by pointer b.

So I think this means that there is no actual resource leak here, but that Coverity just has no way to detect it. I'm a bit rusty with C++ though, so hoping someone can verify that.