Memory leak during SoDB cleanup

Create issue
Issue #73 resolved
Konstantinos Dalamagkidis created an issue

Doing SoDB::init() and then SoDB::finish() should cleanup all memory according to the documentation of the latter, but in my case valgrind reported a memory leak.

The problem lies with the instantiation of the realTime SoGlobalField that is not properly deleted. I am not sure why the d'tor needs to be protected, but as it stands it is never called. I have attached a patch that makes the d'tor public and deletes the object in the callback.

I haven't tested this extensively so I don't know if it has any repercussions.

Comments (7)

  1. Roy Walmsley


    If I remember correctly I have seen this before, probably in version 2.5, although I can't remember how I fixed it. I currently have a Windows application that uses Coin 4. Although Visual Studio always reports three memory leaks, these are all associated with static variables and there is no reported problem with the "realTime" global field. I can see that that an 'atexit' function is used to 'unref' the field. But when I put a debugging breakpoint on the function it didn't seem to get called.

    I will have a further look and get back to you.


  2. Konstantinos Dalamagkidis reporter

    Hi Roy,

    Are you talking about SoDBP::removeRealTimeField not being called? In my system (linux) this does get called but it does not unref the field. Changing that function to just do SoGlobalField::getGlobalFieldContainer("realTime")->unref() fixes the memory leak problem for me. I think the SoGlobalField::removeGlobalFieldContainer(field) is not needed because it is taken care of in the d'tor of SoGlobalField.

    Unfortunately I am not familiar with Coin to help much, I only use it indirectly.

    cheers Konstantinos

  3. Roy Walmsley

    Hi Konstantinos,

    I have rechecked your issue in my Windows program. This is based on Coin4, whereas I know you are using Coin 3.1.3. In my program the SoDBP::removeRealTimeFieldCB function was called and the global field unreferenced. I further checked that the reference count was reduced to zero and that the field was actually deleted. My conclusion is, at least in Coin 4, that this isn't a problem.


  4. Roy Walmsley

    Hi again, Konstantinos

    Apologies. I checked again and realised that I had modified my program from the original. You are correct. There is a problem there.


  5. Log in to comment