From bd7766b17e18873ffc240a6c0b1684432f7be26c Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 11 Feb 2018 21:55:57 +0800 Subject: [PATCH] Prevent small memory leak --- native/jni/utils/misc.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/native/jni/utils/misc.c b/native/jni/utils/misc.c index 88bc1ee45..326fd9392 100644 --- a/native/jni/utils/misc.c +++ b/native/jni/utils/misc.c @@ -51,7 +51,7 @@ int check_data() { struct vector v; vec_init(&v); file_to_vector("/proc/mounts", &v); - char *line, *crypto; + char *line; int mnt = 0; vec_for_each(&v, line) { if (strstr(line, " /data ")) { @@ -61,9 +61,28 @@ int check_data() { } } vec_deep_destroy(&v); - // /data is mounted and not tmpfs and data is unencrypted or vold is started - return mnt && (((crypto = getprop("ro.crypto.state")) && strcmp(crypto, "unencrypted") == 0) - || getprop("init.svc.vold")); + int data = 0; + if (mnt) { + char *crypto = getprop("ro.crypto.state"); + if (crypto != NULL) { + if (strcmp(crypto, "unencrypted") == 0) { + // Unencrypted, we can directly access data + data = 1; + } else { + // Encrypted, check whether vold is started + char *vold = getprop("init.svc.vold"); + if (vold != NULL) { + free(vold); + data = 1; + } + } + free(crypto); + } else { + // ro.crypto.state is not set, assume it's unencrypted + data = 1; + } + } + return data; } /* All the string should be freed manually!! */