From 998a61dd93d18eed837f038c249ec45b023aad10 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 2 Mar 2017 15:07:56 +0100 Subject: [PATCH] Fix minor issues reported by `cppcheck` (cherry picked from commit d7c676a5d42d5d7e5078a8662d355c9a782bdb51) --- pdns/arguments.cc | 1 + pdns/iputils.hh | 17 +++++++++++++---- pdns/nproxy.cc | 8 ++++++-- pdns/pdns_recursor.cc | 7 +++++-- pdns/qtype.cc | 3 +-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pdns/arguments.cc b/pdns/arguments.cc index 491e018b80..10c522ab7e 100644 --- a/pdns/arguments.cc +++ b/pdns/arguments.cc @@ -495,6 +495,7 @@ void ArgvMap::gatherIncludes(std::vector &extraConfigs) { // ensure it's readable file if (stat(namebuf.str().c_str(), &st) || !S_ISREG(st.st_mode)) { L << Logger::Error << namebuf.str() << " is not a file" << std::endl; + closedir(dir); throw ArgException(namebuf.str() + " does not exist!"); } extraConfigs.push_back(namebuf.str()); diff --git a/pdns/iputils.hh b/pdns/iputils.hh index e51acae93a..683d9e9bfb 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -711,8 +711,12 @@ public: bits++; } if (node) { - for(auto it = _nodes.begin(); it != _nodes.end(); it++) - if (node->node4.get() == *it) _nodes.erase(it); + for(auto it = _nodes.begin(); it != _nodes.end(); ) { + if (node->node4.get() == *it) + it = _nodes.erase(it); + else + it++; + } node->node4.reset(); } } else { @@ -732,8 +736,13 @@ public: bits++; } if (node) { - for(auto it = _nodes.begin(); it != _nodes.end(); it++) - if (node->node6.get() == *it) _nodes.erase(it); + for(auto it = _nodes.begin(); it != _nodes.end(); ) { + if (node->node6.get() == *it) + it = _nodes.erase(it); + else + it++; + } + node->node6.reset(); } } diff --git a/pdns/nproxy.cc b/pdns/nproxy.cc index cf91e0a030..b31387a73b 100644 --- a/pdns/nproxy.cc +++ b/pdns/nproxy.cc @@ -78,9 +78,11 @@ try { char buffer[1500]; struct NotificationInFlight nif; + /* make sure we report enough room for IPv6 */ + nif.source.sin4.sin_family = AF_INET6; nif.origSocket = fd; - socklen_t socklen=sizeof(nif.source); + socklen_t socklen=nif.source.getSocklen(); int res=recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&nif.source, &socklen); if(!res) @@ -149,8 +151,10 @@ try { char buffer[1500]; struct NotificationInFlight nif; + /* make sure we report enough room for IPv6 */ + nif.source.sin4.sin_family = AF_INET6; - socklen_t socklen=sizeof(nif.source); + socklen_t socklen=nif.source.getSocklen(); int len=recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr*)&nif.source, &socklen); if(!len) diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index fc74774625..02ec0b97be 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -2110,9 +2110,12 @@ void handlePipeRequest(int fd, FDMultiplexer::funcparam_t& var) if(g_logCommonErrors) L<wantAnswer) - if(write(g_pipes[t_id].writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) + if(tmsg->wantAnswer) { + if(write(g_pipes[t_id].writeFromThread, &resp, sizeof(resp)) != sizeof(resp)) { + delete tmsg; unixDie("write to thread pipe returned wrong size or error"); + } + } delete tmsg; } diff --git a/pdns/qtype.cc b/pdns/qtype.cc index 9bd671db7f..70240fd704 100644 --- a/pdns/qtype.cc +++ b/pdns/qtype.cc @@ -110,8 +110,7 @@ QType &QType::operator=(const string &s) } -QType::QType(uint16_t n) +QType::QType(uint16_t n): QType() { - QType(); code=n; } -- 2.47.2