From 0ab6ffefb43c38aa036e7368454a89807bfef9f7 Mon Sep 17 00:00:00 2001 From: yuchenlin Date: Thu, 20 Sep 2018 22:48:36 +0800 Subject: [PATCH] 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: yuchenlin --- native/jni/utils/misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/jni/utils/misc.c b/native/jni/utils/misc.c index 422a52577..1dce719c2 100644 --- a/native/jni/utils/misc.c +++ b/native/jni/utils/misc.c @@ -184,9 +184,9 @@ int check_proc_name(int pid, const char *name) { sprintf(buf, "/proc/%d/cmdline", pid); f = fopen(buf, "r"); fgets(buf, sizeof(buf), f); + fclose(f); if (strcmp(basename(buf), name) == 0) return 1; - fclose(f); sprintf(buf, "/proc/%d/exe", pid); if (access(buf, F_OK) != 0)