From 6f1142080a8ef3e9d1a4f71989de0a0b57658cb3 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 24 Nov 2015 17:45:00 +0100 Subject: [PATCH] Fix free of buffer which was not allocated Coverity bug report: CID 1270420 "Free of address-of expression" Signed-off-by: Stefan Weil --- classify/clusttool.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/classify/clusttool.cpp b/classify/clusttool.cpp index 9e3fe3114..d86c3a240 100644 --- a/classify/clusttool.cpp +++ b/classify/clusttool.cpp @@ -279,17 +279,22 @@ PROTOSTYLE ReadProtoStyle(FILE *File) { * @note History: 6/6/89, DSJ, Created. */ FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) { + bool needs_free = false; int i; int NumFloatsRead; - if (Buffer == NULL) + if (Buffer == NULL) { Buffer = reinterpret_cast(Emalloc(N * sizeof(FLOAT32))); + needs_free = true; + } for (i = 0; i < N; i++) { NumFloatsRead = tfscanf(File, "%f", &(Buffer[i])); if (NumFloatsRead != 1) { if ((NumFloatsRead == EOF) && (i == 0)) { - Efree(Buffer); + if (needs_free) { + Efree(Buffer); + } return NULL; } else { DoError(ILLEGALFLOAT, "Illegal float specification");