From 46aad00f16bb7d9e5bbe9b387d7dc563fe529cb5 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 3 Aug 2018 21:30:44 +0800 Subject: [PATCH] Use buffer on stack --- native/jni/core/bootstages.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/native/jni/core/bootstages.c b/native/jni/core/bootstages.c index a493f7525..737606ea0 100644 --- a/native/jni/core/bootstages.c +++ b/native/jni/core/bootstages.c @@ -22,7 +22,7 @@ #include "resetprop.h" #include "magiskpolicy.h" -static char *buf, *buf2; +static char buf[PATH_MAX], buf2[PATH_MAX]; static struct vector module_list; extern char **environ; @@ -118,7 +118,6 @@ static void set_path(struct vector *v) { char buffer[512]; for (int i = 0; environ[i]; ++i) { if (strncmp(environ[i], "PATH=", 5) == 0) { - // Prepend BBPATH to PATH sprintf(buffer, "PATH="BBPATH":%s", environ[i] + 5); vec_push_back(v, strdup(buffer)); } else { @@ -532,10 +531,6 @@ void startup() { // No uninstaller or core-only mode if (access(DISABLEFILE, F_OK) != 0) { - // Allocate buffer - buf = xmalloc(PATH_MAX); - buf2 = xmalloc(PATH_MAX); - simple_mount("/system"); simple_mount("/vendor"); } @@ -549,7 +544,6 @@ void startup() { DIR *dir; struct dirent *entry; int root, sbin, fd; - char buf[PATH_MAX]; void *magisk, *init; size_t magisk_size, init_size; @@ -717,8 +711,6 @@ void post_fs_data(int client) { "/sbin/magiskpolicy", "--save", TMPSEPOLICY, "allow "SEPOL_PROC_DOMAIN" * * *", NULL); // Allocate buffer - buf = xmalloc(PATH_MAX); - buf2 = xmalloc(PATH_MAX); vec_init(&module_list); // Merge, trim, mount magisk.img, which will also travel through the modules @@ -835,10 +827,6 @@ void late_start(int client) { return; } - // Allocate buffer - if (buf == NULL) buf = xmalloc(PATH_MAX); - if (buf2 == NULL) buf2 = xmalloc(PATH_MAX); - auto_start_magiskhide(); if (full_patch_pid > 0) { @@ -878,9 +866,6 @@ core_only: } } - // All boot stage done, cleanup everything - free(buf); - free(buf2); - buf = buf2 = NULL; + // All boot stage done, cleanup vec_deep_destroy(&module_list); }