summaryrefslogtreecommitdiffstats
path: root/src/Hooks
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-22 12:36:41 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-22 12:36:41 +0200
commitb1cc33e1227d6ab47781a47f7a88da24e57f4e17 (patch)
treebbe61abb08b19dcf5b94ddb3e5afaa094cf98539 /src/Hooks
parentb21a17491ab4eab43b871da791a8a8ef84489be1 (diff)
downloadabrt-b1cc33e1227d6ab47781a47f7a88da24e57f4e17.tar.gz
abrt-b1cc33e1227d6ab47781a47f7a88da24e57f4e17.tar.xz
abrt-b1cc33e1227d6ab47781a47f7a88da24e57f4e17.zip
fix several resource leaks on error paths
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'src/Hooks')
-rw-r--r--src/Hooks/CCpp.cpp33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/Hooks/CCpp.cpp b/src/Hooks/CCpp.cpp
index 2a7e60c2..27c813fe 100644
--- a/src/Hooks/CCpp.cpp
+++ b/src/Hooks/CCpp.cpp
@@ -79,20 +79,23 @@ char* get_cmdline(const char* pid)
FILE* fp = fopen(path, "r");
int ch;
int ii = 0;
- while ((ch = fgetc(fp)) != EOF)
+ if (fp)
{
- if (ch == 0)
+ while ((ch = fgetc(fp)) != EOF && ii < COMMAND_LINE_SIZE-1)
{
- cmdline[ii] = ' ';
- }
- else if (isspace(ch) || (isascii(ch) && !iscntrl(ch)))
- {
- cmdline[ii] = ch;
+ if (ch == 0)
+ {
+ cmdline[ii] = ' ';
+ }
+ else if (isspace(ch) || (isascii(ch) && !iscntrl(ch)))
+ {
+ cmdline[ii] = ch;
+ }
+ ii++;
}
- ii++;
+ fclose(fp);
}
cmdline[ii] = '\0';
- fclose(fp);
return strdup(cmdline);
}
@@ -103,23 +106,19 @@ int daemon_is_ok()
char pid[PID_MAX];
char path[PATH_MAX];
struct stat buff;
- FILE* fp;
- if ((fp = fopen(VAR_RUN_PID_FILE, "r")) == NULL)
+ FILE* fp = fopen(VAR_RUN_PID_FILE, "r");
+ if (fp == NULL)
{
return 0;
}
fgets(pid, sizeof(pid), fp);
- if (strrchr(pid, '\n') != NULL)
- {
- char* newline = strrchr(pid, '\n');
- *newline = '\0';
- }
+ fclose(fp);
+ *strchrnul(pid, '\n') = '\0';
snprintf(path, sizeof(path), "/proc/%s/stat", pid);
if (stat(path, &buff) == -1)
{
return 0;
}
- fclose(fp);
return 1;
}