Skip to content

Commit

Permalink
Fix free of buffer which was not allocated
Browse files Browse the repository at this point in the history
Coverity bug report: CID 1270420 "Free of address-of expression"

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Nov 27, 2015
1 parent 198ee0a commit 6f11420
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions classify/clusttool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FLOAT32*>(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");
Expand Down

0 comments on commit 6f11420

Please sign in to comment.