From ed442fe3eb4e35279653e4c8c758ffcb0b4aa20a Mon Sep 17 00:00:00 2001 From: Maurizio Lombardi Date: Tue, 25 Jun 2024 13:30:50 +0200 Subject: [PATCH] linux: avoid potential null pointer dereference if the "result" pointer is null because of a memory allocation failure, do not dereference it and do not free the old pointer. Signed-off-by: Maurizio Lombardi --- src/nvme/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvme/util.c b/src/nvme/util.c index 7404509e..ce0ce763 100644 --- a/src/nvme/util.c +++ b/src/nvme/util.c @@ -1144,7 +1144,7 @@ void *__nvme_realloc(void *p, size_t len) void *result = __nvme_alloc(len); - if (p) { + if (p && result) { memcpy(result, p, min(old_len, len)); free(p); }