Page 1 of 1

Exception.cpp/throwException: memory leak with nested exceptions

Posted: 2017-02-09T08:48:53-07:00
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?

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

Posted: 2017-02-09T13:57:16-07:00
by dlemstra
Thanks for reporting this issue. I just pushed a fix for this to our git repository.

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

Posted: 2017-02-09T14:25:34-07:00
by tc33
Great, thank you!