Fix: prevent dangling pointer in utils_partial_realpath
[lttng-tools.git] / src / common / utils.c
index 7a09259ebc6b8de4657f804146bb795c35ac023e..bf6751ebb95c4e121d4e8a2bf9c45dd858d4efe2 100644 (file)
@@ -52,7 +52,7 @@
 LTTNG_HIDDEN
 char *utils_partial_realpath(const char *path, char *resolved_path, size_t size)
 {
-       char *cut_path, *try_path = NULL, *try_path_prev = NULL;
+       char *cut_path = NULL, *try_path = NULL, *try_path_prev = NULL;
        const char *next, *prev, *end;
 
        /* Safety net */
@@ -121,6 +121,7 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size)
 
                /* Free the allocated memory */
                free(cut_path);
+               cut_path = NULL;
        };
 
        /* Allocate memory for the resolved path if necessary */
@@ -171,6 +172,7 @@ char *utils_partial_realpath(const char *path, char *resolved_path, size_t size)
 
 error:
        free(resolved_path);
+       free(cut_path);
        return NULL;
 }
 
This page took 0.023579 seconds and 4 git commands to generate.