summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d0d845e)
raw | patch | inline | side by side (parent: d0d845e)
author | Florian Forster <octo@collectd.org> | |
Wed, 20 Feb 2013 08:06:39 +0000 (09:06 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Wed, 20 Feb 2013 08:06:39 +0000 (09:06 +0100) |
This prevents file descriptors and memory from leaking if something goes
wrong, e.g. the last line in the file is a comment.
wrong, e.g. the last line in the file is a comment.
src/snort.c | patch | blob | history |
diff --git a/src/snort.c b/src/snort.c
index 6e7e4a7f4ab8e63346c12a4427c4d6e5d88a431a..a49cb5fe52a0b1f4c7b061fba733d02a426a2a99 100644 (file)
--- a/src/snort.c
+++ b/src/snort.c
if ((fstat(fd, &sb) != 0) || (!S_ISREG(sb.st_mode))){
ERROR("snort plugin: `%s' is not a file.", id->path);
+ close (fd);
return (-1);
}
if (sb.st_size == 0){
ERROR("snort plugin: `%s' is empty.", id->path);
+ close (fd);
return (-1);
}
/* offset = */ 0);
if (p_start == MAP_FAILED){
ERROR("snort plugin: mmap error");
+ close (fd);
return (-1);
}
if (metrics_num == 1){
ERROR("snort plugin: last line of `%s' does not contain enough values.", id->path);
+ close (fd);
+ munmap(p_start, sb.st_size);
return (-1);
}
if (*p_end == '#'){
ERROR("snort plugin: last line of `%s' is a comment.", id->path);
+ close (fd);
+ munmap(p_start, sb.st_size);
return (-1);
}
metrics = calloc (metrics_num, sizeof (*metrics));
if (metrics == NULL) {
ERROR ("snort plugin: calloc failed.");
+ sfree (buf);
return (-1);
}