From c2cef3d1d826a022a412cd37d2506ef1b0f79dfd Mon Sep 17 00:00:00 2001 From: Jack Mousseau Date: Sun, 18 Feb 2024 07:23:31 -0800 Subject: [PATCH] Prevent memory leak when tensor type is invalid --- gguflib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gguflib.c b/gguflib.c index 7aa2696..96e66b1 100644 --- a/gguflib.c +++ b/gguflib.c @@ -902,6 +902,7 @@ float *gguf_tensor_to_float(gguf_tensor *tensor) { } else if (tensor->type == GGUF_TYPE_Q4_1) { gguf_q4_1_to_float(tensor->weights_data, f, tensor->num_weights, NULL); } else { + free(f); errno = EINVAL; return NULL; } @@ -931,6 +932,7 @@ int16_t *gguf_tensor_to_f16(gguf_tensor *tensor) { } else if (tensor->type == GGUF_TYPE_Q4_1) { gguf_q4_1_to_float(tensor->weights_data, f16, tensor->num_weights, gguf_store_f16_callback); } else { + free(f16); errno = EINVAL; return NULL; }