Commit 0ab6ffef authored by yuchenlin's avatar yuchenlin Committed by John Wu

utils/misc.c: prevent file staying opened when function leaving

The utils function may be called in any situation, such as in daemon. We
should guarantee that all the resource got from this function released
normally.
Signed-off-by: 's avataryuchenlin <npes87184@gmail.com>
parent a292a1d2
...@@ -184,9 +184,9 @@ int check_proc_name(int pid, const char *name) { ...@@ -184,9 +184,9 @@ int check_proc_name(int pid, const char *name) {
sprintf(buf, "/proc/%d/cmdline", pid); sprintf(buf, "/proc/%d/cmdline", pid);
f = fopen(buf, "r"); f = fopen(buf, "r");
fgets(buf, sizeof(buf), f); fgets(buf, sizeof(buf), f);
fclose(f);
if (strcmp(basename(buf), name) == 0) if (strcmp(basename(buf), name) == 0)
return 1; return 1;
fclose(f);
sprintf(buf, "/proc/%d/exe", pid); sprintf(buf, "/proc/%d/exe", pid);
if (access(buf, F_OK) != 0) if (access(buf, F_OK) != 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment