]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix potential memory leak on GopherStateData constructor errors
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 1 Oct 2015 12:35:09 +0000 (05:35 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 1 Oct 2015 12:35:09 +0000 (05:35 -0700)
In the unusual event that the GopherStateData object constructor fails
it is possible that the destructor gets called without having gone
through the deleteThis() and swangSong() dance. Since the constructor
allocates memory buffer we need to clean that up.

 Detected by Coverity Scan. Issue 1318022

src/gopher.cc

index 3dcaf9cb8a8cd5759cfac0baafcdd5b5489eeebd..e151f928a65df2474c15084f9c61a03898f2b5a7 100644 (file)
@@ -97,6 +97,7 @@ public:
         entry->lock("gopherState");
         *replybuf = 0;
     }
+    ~GopherStateData() {if(buf) swanSong();}
 
     /* AsyncJob API emulated */
     void deleteThis(const char *aReason);
@@ -166,8 +167,10 @@ GopherStateData::swanSong()
     if (entry)
         entry->unlock("gopherState");
 
-    if (buf)
+    if (buf) {
         memFree(buf, MEM_4K_BUF);
+        buf = nullptr;
+    }
 }
 
 /**