From 23541b3e6b0c01ad6701321551bf7559d16659de Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Mon, 29 Sep 2014 00:18:13 -0700 Subject: [PATCH] Cleanup: fix various uninitialized class members Also, simplify some destructors. xfree() is faster than safe_free() and both are ok in a destructor. Detected by Coverity Scan. Issue 740527, 740532, 740533, 740534, 740563, 1241964 --- src/StoreMetaUnpacker.cc | 11 +++++++++-- src/adaptation/icap/History.cc | 7 +++++-- src/adaptation/icap/Options.cc | 10 +++++++--- src/adaptation/icap/Xaction.cc | 13 +++++++++---- src/external_acl.cc | 2 +- src/fs/ufs/UFSSwapDir.cc | 16 ++++++++++++++-- 6 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/StoreMetaUnpacker.cc b/src/StoreMetaUnpacker.cc index 447f862963..8576086d03 100644 --- a/src/StoreMetaUnpacker.cc +++ b/src/StoreMetaUnpacker.cc @@ -61,9 +61,16 @@ StoreMetaUnpacker::getBufferLength() memcpy(hdr_len, &buf[1], sizeof(int)); } -StoreMetaUnpacker::StoreMetaUnpacker (char const *aBuffer, ssize_t aLen, int *anInt) : buf (aBuffer), buflen(aLen), hdr_len(anInt), position(1 + sizeof(int)) +StoreMetaUnpacker::StoreMetaUnpacker(char const *aBuffer, ssize_t aLen, int *anInt) : + buf(aBuffer), + buflen(aLen), + hdr_len(anInt), + position(1 + sizeof(int)), + type('\0'), + length(0), + tail(NULL) { - assert (aBuffer != NULL); + assert(aBuffer != NULL); } void diff --git a/src/adaptation/icap/History.cc b/src/adaptation/icap/History.cc index ee32fefafb..a32b96619e 100644 --- a/src/adaptation/icap/History.cc +++ b/src/adaptation/icap/History.cc @@ -13,9 +13,12 @@ #include "SquidTime.h" Adaptation::Icap::History::History(): - logType(LOG_TAG_NONE), req_sz(0), - pastTime(0), concurrencyLevel(0) + logType(LOG_TAG_NONE), + req_sz(0), + pastTime(0), + concurrencyLevel(0) { + memset(¤tStart, 0, sizeof(currentStart)); } void Adaptation::Icap::History::start(const char *context) diff --git a/src/adaptation/icap/Options.cc b/src/adaptation/icap/Options.cc index 2c3317c2bd..15e33e2343 100644 --- a/src/adaptation/icap/Options.cc +++ b/src/adaptation/icap/Options.cc @@ -15,10 +15,14 @@ #include "StrList.h" #include "wordlist.h" -Adaptation::Icap::Options::Options(): error("unconfigured"), - max_connections(-1), allow204(false), +Adaptation::Icap::Options::Options() : + error("unconfigured"), + max_connections(-1), + allow204(false), allow206(false), - preview(-1), theTTL(-1) + preview(-1), + theTTL(-1), + theTimestamp(0) { theTransfers.preview.name = "Transfer-Preview"; theTransfers.preview.kind = xferPreview; diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index 23a3c76414..b69d040159 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -32,8 +32,6 @@ #include "SquidConfig.h" #include "SquidTime.h" -//CBDATA_NAMESPACED_CLASS_INIT(Adaptation::Icap, Xaction); - Adaptation::Icap::Xaction::Xaction(const char *aTypeName, Adaptation::Icap::ServiceRep::Pointer &aService): AsyncJob(aTypeName), Adaptation::Initiate(aTypeName), @@ -42,13 +40,18 @@ Adaptation::Icap::Xaction::Xaction(const char *aTypeName, Adaptation::Icap::Serv attempts(0), connection(NULL), theService(aService), - commBuf(NULL), commBufSize(0), + commBuf(NULL), + commBufSize(0), commEof(false), reuseConnection(true), isRetriable(true), isRepeatable(true), ignoreLastWrite(false), - connector(NULL), reader(NULL), writer(NULL), closer(NULL), + stopReason(NULL), + connector(NULL), + reader(NULL), + writer(NULL), + closer(NULL), alep(new AccessLogEntry), al(*alep), cs(NULL) @@ -58,6 +61,8 @@ Adaptation::Icap::Xaction::Xaction(const char *aTypeName, Adaptation::Icap::Serv icapRequest = new HttpRequest; HTTPMSGLOCK(icapRequest); icap_tr_start = current_time; + memset(&icap_tio_start, 0, sizeof(icap_tio_start)); + memset(&icap_tio_finish, 0, sizeof(icap_tio_finish)); } Adaptation::Icap::Xaction::~Xaction() diff --git a/src/external_acl.cc b/src/external_acl.cc index 8c0ba8a632..cf9842418b 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -72,7 +72,7 @@ public: typedef RefCount Pointer; MEMPROXY_CLASS(external_acl_format); - external_acl_format() : header(NULL), member(NULL), separator(' ') {} + external_acl_format() : type(Format::LFT_NONE), header(NULL), member(NULL), separator(' '), header_id(HDR_BAD_HDR) {} ~external_acl_format() { xfree(header); xfree(member); diff --git a/src/fs/ufs/UFSSwapDir.cc b/src/fs/ufs/UFSSwapDir.cc index 6fab4f0a7c..52179c90a9 100644 --- a/src/fs/ufs/UFSSwapDir.cc +++ b/src/fs/ufs/UFSSwapDir.cc @@ -304,7 +304,19 @@ Fs::Ufs::UFSSwapDir::create() createSwapSubDirs(); } -Fs::Ufs::UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(new FileMap()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType)), cur_size(0), n_disk_objects(0) +Fs::Ufs::UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : + SwapDir(aType), + IO(NULL), + fsdata(NULL), + map(new FileMap()), + suggest(0), + l1(16), + l2(256), + swaplog_fd(-1), + currentIOOptions(new ConfigOptionVector()), + ioType(xstrdup(anIOType)), + cur_size(0), + n_disk_objects(0) { /* modulename is only set to disk modules that are built, by configure, * so the Find call should never return NULL here. @@ -318,7 +330,7 @@ Fs::Ufs::UFSSwapDir::~UFSSwapDir() file_close(swaplog_fd); swaplog_fd = -1; } - safe_free(ioType); + xfree(ioType); delete map; delete IO; delete currentIOOptions; -- 2.47.2