From: Amos Jeffries Date: Thu, 1 Oct 2015 12:35:09 +0000 (-0700) Subject: Fix potential memory leak on GopherStateData constructor errors X-Git-Tag: SQUID_4_0_1~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=58d27a9092c337ca7f02c13470737d6fcaa1c24a;p=thirdparty%2Fsquid.git Fix potential memory leak on GopherStateData constructor errors 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 --- diff --git a/src/gopher.cc b/src/gopher.cc index 3dcaf9cb8a..e151f928a6 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -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; + } } /**