Exception.cpp/throwException: memory leak with nested exceptions

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Exception.cpp/throwException: memory leak with nested exceptions

Post by tc33 »

Code: Select all

if (exception_->exceptions != (void *) NULL)
    {
      index=GetNumberOfElementsInLinkedList((LinkedListInfo *)
        exception_->exceptions);
      while(index > 0)
      {
        p=(const ExceptionInfo *) GetValueFromLinkedList((LinkedListInfo *)
          exception_->exceptions,--index);
        if ((p->severity != exception_->severity) || (LocaleCompare(p->reason,
            exception_->reason) != 0) || (LocaleCompare(p->description,
            exception_->description) != 0))
          {
            if (nestedException == (Exception *) NULL)
              nestedException=createException(p);  // root exception created
            else
              {
                q=createException(p);
                nestedException->nested(q);
                nestedException=q;  // leaf exception overwrites previous root/leaf value...what happens to that pointer?
              }
          }
      }
    }
    
    ...
    
    throw XXX(message,nestedException);   // leaf exception is passed to exception ctor, so only that leaf exception gets deleted on exception dtor
    
    
The issue appears to be caused by the 'nestedException=q;' line...at what point does the pointer that was previously created ever get deleted? AFAICT, only the last nestedException pointer is passed to the resulting Exception object, therefore any previously-created exceptions created are lost/leaked.

Perhaps the resulting Exception object should be based on the first/root nestedException rather than the last/leaf exception?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Exception.cpp/throwException: memory leak with nested exceptions

Post by dlemstra »

Thanks for reporting this issue. I just pushed a fix for this to our git repository.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Re: Exception.cpp/throwException: memory leak with nested exceptions

Post by tc33 »

Great, thank you!
Post Reply