]> git.feebdaed.xyz Git - 0xmirror/radare2.git/commitdiff
Some more resource leaks fixed in r2r
authorpancake <trufae@gmail.com>
Sun, 7 Dec 2025 21:34:23 +0000 (22:34 +0100)
committerGitHub <noreply@github.com>
Sun, 7 Dec 2025 21:34:23 +0000 (22:34 +0100)
binr/r2r/r2r.c
binr/r2r/run.c

index 3174aa655e2cc30a6aef347382be8818a313f467..5cfefede3c72232ac5c146be48a03b77354c2809 100644 (file)
@@ -185,7 +185,7 @@ static char *makepath(void) {
        if (!make) {
                make = r_file_path ("make");
        }
-       return NULL;
+       return make;
 }
 
 static bool r2r_test_run_unit(void) {
@@ -441,10 +441,12 @@ static bool r2r_setup_directory(R2ROptions *opt, int arg_ind, int argc, char **a
 }
 
 static void r2r_setup_environment(void) {
-       if (!r_sys_getenv ("R2_BIN")) {
+       char *r2_bin = r_sys_getenv ("R2_BIN");
+       if (!r2_bin) {
                r_sys_setenv ("R2_BIN", R2_BINDIR);
                r_sys_setenv_sep ("PATH", R2_BINDIR, false);
        }
+       free (r2_bin);
        char *have_options = r_sys_getenv ("ASAN_OPTIONS");
        if (have_options) {
                free (have_options);
@@ -524,6 +526,7 @@ static int r2r_load_tests(R2RState *state, R2ROptions *opt, int arg_ind, int arg
                int i;
                for (i = arg_ind; i < argc; i++) {
                        const char *arg = argv[i];
+                       char *arg_str = NULL;
                        if (*arg == '@') {
                                arg++;
                                eprintf ("Category: %s\n", arg);
@@ -548,7 +551,8 @@ static int r2r_load_tests(R2RState *state, R2ROptions *opt, int arg_ind, int arg
                                } else if (!strcmp (arg, "cmds")) {
                                        arg = "db";
                                } else {
-                                       arg = r_str_newf ("db/%s", arg + 1);
+                                       arg_str = r_str_newf ("db/%s", arg + 1);
+                                       arg = arg_str;
                                }
                        }
                        if (r_str_endswith (arg, ".c")) {
@@ -571,15 +575,18 @@ static int r2r_load_tests(R2RState *state, R2ROptions *opt, int arg_ind, int arg
                                        }
                                }
                                r_list_free (tests);
+                               free (arg_str);
                                return grc? grc: 1; // Signal special exit
                        }
                        char *tf = r_file_abspath_rel (cwd, arg);
                        if (!tf || !r2r_test_database_load (state->db, tf, skip_json_tests)) {
                                R_LOG_ERROR ("Failed to load tests from \"%s\"", tf);
                                free (tf);
+                               free (arg_str);
                                return -1;
                        }
                        free (tf);
+                       free (arg_str);
                }
        } else {
                if (!r2r_test_database_load (state->db, "db", skip_json_tests)) {
index 998bc8344896ab7dd9d75e4361ae4b3e35d94dab..41521e7751f909c188a8f1b09ba28cc3ff387276 100644 (file)
@@ -293,19 +293,16 @@ beach:
        free (cmdline);
        return proc;
 error:
-       if (proc) {
-               if (proc->stdin_write) {
-                       CloseHandle (proc->stdin_write);
-               }
-               if (proc->stdout_read) {
-                       CloseHandle (proc->stdout_read);
-               }
-               if (proc->stderr_read) {
-                       CloseHandle (proc->stderr_read);
-               }
-               free (proc);
-               proc = NULL;
+       if (proc->stdin_write) {
+               CloseHandle (proc->stdin_write);
        }
+       if (proc->stdout_read) {
+               CloseHandle (proc->stdout_read);
+       }
+       if (proc->stderr_read) {
+               CloseHandle (proc->stderr_read);
+       }
+       R_FREE (proc);
        goto beach;
 }
 
@@ -723,29 +720,29 @@ R_API R2RSubprocess *r2r_subprocess_start(
 
        return proc;
 error:
-       if (proc && proc->killpipe[0] == -1) {
+       if (proc->killpipe[0] != -1) {
                close (proc->killpipe[0]);
        }
-       if (proc && proc->killpipe[1] == -1) {
+       if (proc->killpipe[1] != -1) {
                close (proc->killpipe[1]);
        }
        free (proc);
-       if (stderr_pipe[0] == -1) {
+       if (stderr_pipe[0] != -1) {
                close (stderr_pipe[0]);
        }
-       if (stderr_pipe[1] == -1) {
+       if (stderr_pipe[1] != -1) {
                close (stderr_pipe[1]);
        }
-       if (stdout_pipe[0] == -1) {
+       if (stdout_pipe[0] != -1) {
                close (stdout_pipe[0]);
        }
-       if (stdout_pipe[1] == -1) {
+       if (stdout_pipe[1] != -1) {
                close (stdout_pipe[1]);
        }
-       if (stdin_pipe[0] == -1) {
+       if (stdin_pipe[0] != -1) {
                close (stdin_pipe[0]);
        }
-       if (stdin_pipe[1] == -1) {
+       if (stdin_pipe[1] != -1) {
                close (stdin_pipe[1]);
        }
        r_th_lock_leave (subprocs_mutex);