Close files, cleanup resourses

This commit is contained in:
topjohnwu 2017-05-02 04:55:55 +08:00
parent e16d604d0d
commit 6017ff2318
5 changed files with 17 additions and 12 deletions

View File

@ -62,6 +62,8 @@ static char *loopsetup(const char *img) {
return NULL;
strcpy((char *) info.lo_file_name, img);
ioctl(lfd, LOOP_SET_STATUS64, &info);
close(lfd);
close(ffd);
return strdup(device);
}
@ -241,6 +243,7 @@ static void clone_skeleton(struct node_entry *node, const char *real_path) {
insert_child(node, dummy);
}
}
closedir(dir);
snprintf(buf, PATH_MAX, "/dev/magisk/dummy%s", real_path);
xmkdir_p(buf, 0755);

View File

@ -23,6 +23,7 @@
#include "magiskpolicy.h"
pthread_t sepol_patch;
int null_fd;
static void *request_handler(void *args) {
// Setup the default error handler for threads
@ -111,9 +112,10 @@ void start_daemon() {
xsetsid();
setcon("u:r:su:s0");
umask(022);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
null_fd = xopen("/dev/null", O_RDWR);
xdup2(null_fd, STDIN_FILENO);
xdup2(null_fd, STDOUT_FILENO);
xdup2(null_fd, STDERR_FILENO);
// Patch selinux with medium patch before we do anything
load_policydb(SELINUX_POLICY);

View File

@ -8,6 +8,7 @@
#include <stdio.h>
#include <limits.h>
#include <pthread.h>
#include <unistd.h>
#include "magisk.h"
#include "utils.h"
@ -29,6 +30,7 @@ static void *logger_thread(void *args) {
while (fdgets(buffer, sizeof(buffer), fd)) {
fprintf(logfile, "%s", buffer);
}
close(fd);
return NULL;
}

View File

@ -55,6 +55,7 @@ extern char *argv0; /* For changing process name */
extern char *applet[];
extern int (*applet_main[]) (int, char *[]);
extern int null_fd;
// Multi-call entrypoints
int magiskhide_main(int argc, char *argv[]);

View File

@ -45,17 +45,18 @@ unsigned get_radio_uid() {
}
int check_data() {
int ret = 0;
char buffer[4096];
FILE *fp = xfopen("/proc/mounts", "r");
while (fgets(buffer, sizeof(buffer), fp)) {
if (strstr(buffer, " /data ")) {
if (strstr(buffer, "tmpfs"))
return 0;
else
return 1;
if (strstr(buffer, "tmpfs") == NULL)
ret = 1;
break;
}
}
return 0;
fclose(fp);
return ret;
}
/* All the string should be freed manually!! */
@ -238,10 +239,6 @@ int run_command(int *fd, const char *path, char *const argv[]) {
xdup2(sv[0], STDIN_FILENO);
xdup2(sv[0], STDOUT_FILENO);
xdup2(sv[0], STDERR_FILENO);
} else {
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}
execv(path, argv);