Commit bd7766b1 authored by topjohnwu's avatar topjohnwu

Prevent small memory leak

parent 70b7d734
...@@ -51,7 +51,7 @@ int check_data() { ...@@ -51,7 +51,7 @@ int check_data() {
struct vector v; struct vector v;
vec_init(&v); vec_init(&v);
file_to_vector("/proc/mounts", &v); file_to_vector("/proc/mounts", &v);
char *line, *crypto; char *line;
int mnt = 0; int mnt = 0;
vec_for_each(&v, line) { vec_for_each(&v, line) {
if (strstr(line, " /data ")) { if (strstr(line, " /data ")) {
...@@ -61,9 +61,28 @@ int check_data() { ...@@ -61,9 +61,28 @@ int check_data() {
} }
} }
vec_deep_destroy(&v); vec_deep_destroy(&v);
// /data is mounted and not tmpfs and data is unencrypted or vold is started int data = 0;
return mnt && (((crypto = getprop("ro.crypto.state")) && strcmp(crypto, "unencrypted") == 0) if (mnt) {
|| getprop("init.svc.vold")); 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!! */ /* All the string should be freed manually!! */
......
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