Skip to content

Commit 6f11420

Browse files
committed
Fix free of buffer which was not allocated
Coverity bug report: CID 1270420 "Free of address-of expression" Signed-off-by: Stefan Weil <[email protected]>
1 parent 198ee0a commit 6f11420

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

classify/clusttool.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,22 @@ PROTOSTYLE ReadProtoStyle(FILE *File) {
279279
* @note History: 6/6/89, DSJ, Created.
280280
*/
281281
FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
282+
bool needs_free = false;
282283
int i;
283284
int NumFloatsRead;
284285

285-
if (Buffer == NULL)
286+
if (Buffer == NULL) {
286287
Buffer = reinterpret_cast<FLOAT32*>(Emalloc(N * sizeof(FLOAT32)));
288+
needs_free = true;
289+
}
287290

288291
for (i = 0; i < N; i++) {
289292
NumFloatsRead = tfscanf(File, "%f", &(Buffer[i]));
290293
if (NumFloatsRead != 1) {
291294
if ((NumFloatsRead == EOF) && (i == 0)) {
292-
Efree(Buffer);
295+
if (needs_free) {
296+
Efree(Buffer);
297+
}
293298
return NULL;
294299
} else {
295300
DoError(ILLEGALFLOAT, "Illegal float specification");

0 commit comments

Comments
 (0)