Fix malloc check

This commit is contained in:
savalet
2025-02-15 13:11:28 +01:00
parent b78fc1b1c1
commit ce39f597f3
3 changed files with 5 additions and 1 deletions

View File

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

View File

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

View File

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