Skip to content

Commit 754addb

Browse files
committed
stats: fixed issues reported by coverity
1 parent e29b0f2 commit 754addb

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

ipfixprobe.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ void serve_stat_clients(ipxp_conf_t &conf, struct pollfd pfds[2])
543543
int fd = accept(pfds[0].fd, NULL, NULL);
544544
if (pfds[1].fd == -1) {
545545
pfds[1].fd = fd;
546-
} else {
546+
} else if (fd != -1) {
547+
// Close incoming connection
547548
close(fd);
548549
}
549550
}

ipfixprobe_stats.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,29 @@ int main(int argc, char *argv[])
104104
std::string path;
105105
IpfixStatsParser parser;
106106

107+
107108
signal(SIGTERM, signal_handler);
108109
signal(SIGINT, signal_handler);
109-
110110
try {
111111
parser.parse(argc - 1, const_cast<const char **>(argv) + 1);
112-
} catch (ParserError &e) {
112+
113+
if (parser.m_help) {
114+
parser.usage(std::cout, 0);
115+
goto EXIT;
116+
}
117+
118+
path = DEFAULTSOCKETDIR "/ipfixprobe_" + std::to_string(parser.m_pid) + ".sock";
119+
fd = connect_to_exporter(path.c_str());
120+
if (fd == -1) {
121+
error("connecting to exporter");
122+
goto EXIT;
123+
}
124+
} catch (std::runtime_error &e) {
113125
error(e.what());
114126
status = EXIT_FAILURE;
115127
goto EXIT;
116128
}
117129

118-
if (parser.m_help) {
119-
parser.usage(std::cout, 0);
120-
goto EXIT;
121-
}
122-
123-
path = DEFAULTSOCKETDIR "/ipfixprobe_" + std::to_string(parser.m_pid) + ".sock";
124-
fd = connect_to_exporter(path.c_str());
125-
if (fd == -1) {
126-
error("connecting to exporter");
127-
goto EXIT;
128-
}
129130
while (!stop) {
130131
*(uint32_t *) buffer = MSG_MAGIC;
131132
// Send stats data request

stats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int create_stats_sock(const char *path)
8585

8686
unlink(addr.sun_path);
8787
fd = socket(AF_UNIX, SOCK_STREAM, 0);
88-
if (fd) {
88+
if (fd != -1) {
8989
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
9090
perror("unable to bind socket");
9191
close(fd);

0 commit comments

Comments
 (0)