Browse Source

[2836] Don't leak memory on exception

If we throw an exception from the constructor, destructor is not called.
Call the clean-up manually there, so we don't leak memory.
Michal 'vorner' Vaner 12 years ago
parent
commit
5dc80a3df4
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/lib/datasrc/memory/segment_object_holder.h

+ 4 - 0
src/lib/datasrc/memory/segment_object_holder.h

@@ -47,6 +47,10 @@ public:
         holder_name_(getNextHolderName()), holding_(true)
     {
         if (mem_sgmt_.setNamedAddress(holder_name_.c_str(), NULL)) {
+            // OK. We've grown. The caller might need to be informed, so
+            // we throw. But then, we don't get our destructor, so we
+            // release the memory right away.
+            mem_sgmt_.clearNamedAddress(holder_name_.c_str());
             isc_throw(isc::util::MemorySegmentGrown,
                       "Segment grown when allocating holder");
         }