From ce39f597f35217be5f42e3978238a75d064d28c1 Mon Sep 17 00:00:00 2001 From: savalet Date: Sat, 15 Feb 2025 13:11:28 +0100 Subject: [PATCH] Fix malloc check --- src/exec.c | 2 +- ulib/mem/realloc.c | 2 ++ ulib/str/strdup.c | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/exec.c b/src/exec.c index db1deb6..a81fdee 100644 --- a/src/exec.c +++ b/src/exec.c @@ -171,9 +171,9 @@ int execute(char *buffer, env_t *env, history_t *history) return BUILTINS[i].ptr(env, args, buffer); path = get_env_value(env, "PATH"); full_bin_path = find_binary(path, args[0]); - U_DEBUG("Found bin [%s]\n", full_bin_path); if (full_bin_path == NULL) return (free((void *)args), RETURN_FAILURE); + U_DEBUG("Found bin [%s]\n", full_bin_path); status = launch_bin(full_bin_path, args, env, buffer); status_handler(status, history); free(full_bin_path); diff --git a/ulib/mem/realloc.c b/ulib/mem/realloc.c index 0083b48..eee7ebd 100644 --- a/ulib/mem/realloc.c +++ b/ulib/mem/realloc.c @@ -19,6 +19,8 @@ void *u_realloc(void *ptr, size_t actual_size, size_t new_size) if (!actual_size && !new_size) return NULL; new = malloc(new_size); + if (new == NULL) + return NULL; if (actual_size > 0 && new_size > 0) u_memcpy(new, ptr, actual_size); free(ptr); diff --git a/ulib/str/strdup.c b/ulib/str/strdup.c index 3ab6064..cebd182 100644 --- a/ulib/str/strdup.c +++ b/ulib/str/strdup.c @@ -16,6 +16,8 @@ char *u_strdup(char const *src) int len = u_strlen(src); dest = malloc(sizeof(char) * (len + 1)); + if (dest == NULL) + return NULL; u_bzero(dest, len + 1); return u_strcpy(dest, src); }