Use buffer on stack

This commit is contained in:
topjohnwu 2018-08-03 21:30:44 +08:00
parent 252afe8932
commit 46aad00f16

View File

@ -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);
}