Various at-exit-time leaks removed to minimize valgrind false positives. Removing these leaks helps with detecting true leaks, but it is possible that these changes expose other bugs that crash exiting Squid. We have not seen such crashes in our limited tests. Some of this cleanup code used to be enabled in LEAK_CHECK_MODE but then was marked as "broken" in 2006: #if LEAK_CHECK_MODE && 0 /* doesn't work at the moment */ Needless to say, at-exit leaks themselves are harmless because the OS is going to reclaim all process memory after the process exits. However, besides misleading valgrind, some (future?) cleanup code enabled by these changes might affect on-disk or shared memory state. These possible cleanup actions (that may be difficult to track reliably) make re-enabling LEAK_CHECK_MODE conditional for this code not such a good idea. Besides, if we do not enable the cleanup on a permanent basis, the usually unused code may never work correctly. === modified file 'src/main.cc' --- src/main.cc 2014-03-30 12:00:34 +0000 +++ src/main.cc 2014-04-25 00:42:21 +0000 @@ -1894,40 +1894,59 @@ SquidShutdown() fqdncacheFreeMemory(); asnFreeMemory(); clientdbFreeMemory(); httpHeaderCleanModule(); statFreeMemory(); eventFreeMemory(); mimeFreeMemory(); errorClean(); #endif // clear StoreController Store::Root(NULL); fdDumpOpen(); comm_exit(); memClean(); RunRegisteredHere(RegisteredRunner::finishShutdown); +#if USE_SSL_CRTD + Ssl::Helper::GetInstance()->Shutdown(); +#endif +#if USE_SSL +#if 1 // USE_SSL_CERT_VALIDATOR + if (Ssl::CertValidationHelper::GetInstance()) + Ssl::CertValidationHelper::GetInstance()->Shutdown(); +#endif +#endif + + ipcacheFreeMemory(); + fqdncacheFreeMemory(); + mimeFreeMemory(); + errorClean(); + configFreeMemory(); // SSL_CTX_free(Config.ssl_client.sslContext); +#if USE_SSL + CRYPTO_cleanup_all_ex_data(); // once in process lifetime +#endif + if (IamPrimaryProcess()) { if (Config.pidFilename && strcmp(Config.pidFilename, "none") != 0) { enter_suid(); safeunlink(Config.pidFilename, 0); leave_suid(); } } debugs(1, DBG_IMPORTANT, "Squid Cache (Version " << version_string << "): Exiting normally."); /* * DPW 2006-10-23 * We used to fclose(debug_log) here if it was set, but then * we forgot to set it to NULL. That caused some coredumps * because exit() ends up calling a bunch of destructors and * such. So rather than forcing the debug_log to close, we'll * leave it open so that those destructors can write some * debugging if necessary. The file will be closed anyway when * the process truly exits. */ === modified file 'src/mime.cc' --- src/mime.cc 2013-12-19 04:53:35 +0000 +++ src/mime.cc 2014-04-24 20:33:08 +0000 @@ -37,41 +37,40 @@ #include "HttpHdrCc.h" #include "HttpReply.h" #include "HttpRequest.h" #include "internal.h" #include "Mem.h" #include "MemBuf.h" #include "MemObject.h" #include "mime.h" #include "RequestFlags.h" #include "SquidConfig.h" #include "Store.h" #include "StoreClient.h" #if HAVE_SYS_STAT_H #include #endif #define GET_HDR_SZ 1024 /* forward declarations */ -static void mimeFreeMemory(void); static char const *mimeGetIcon(const char *fn); class MimeIcon : public StoreClient { public: explicit MimeIcon(const char *aName); ~MimeIcon(); void setName(char const *); char const * getName() const; void load(); void created(StoreEntry *newEntry); MEMPROXY_CLASS(MimeIcon); private: const char *icon_; char *url_; }; MEMPROXY_CLASS_INLINE(MimeIcon); class MimeEntry === modified file 'src/mime.h' --- src/mime.h 2013-02-01 17:05:58 +0000 +++ src/mime.h 2014-04-24 20:32:03 +0000 @@ -17,28 +17,29 @@ * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ #ifndef SQUID_MIME_H_ #define SQUID_MIME_H_ void mimeInit(char *filename); +void mimeFreeMemory(); const char *mimeGetContentEncoding(const char *fn); const char *mimeGetContentType(const char *fn); const char *mimeGetIconURL(const char *fn); char mimeGetTransferMode(const char *fn); bool mimeGetDownloadOption(const char *fn); bool mimeGetViewOption(const char *fn); #endif /* SQUID_MIME_H_ */