We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 198ee0a commit 6f11420Copy full SHA for 6f11420
classify/clusttool.cpp
@@ -279,17 +279,22 @@ PROTOSTYLE ReadProtoStyle(FILE *File) {
279
* @note History: 6/6/89, DSJ, Created.
280
*/
281
FLOAT32* ReadNFloats(FILE * File, uinT16 N, FLOAT32 Buffer[]) {
282
+ bool needs_free = false;
283
int i;
284
int NumFloatsRead;
285
- if (Buffer == NULL)
286
+ if (Buffer == NULL) {
287
Buffer = reinterpret_cast<FLOAT32*>(Emalloc(N * sizeof(FLOAT32)));
288
+ needs_free = true;
289
+ }
290
291
for (i = 0; i < N; i++) {
292
NumFloatsRead = tfscanf(File, "%f", &(Buffer[i]));
293
if (NumFloatsRead != 1) {
294
if ((NumFloatsRead == EOF) && (i == 0)) {
- Efree(Buffer);
295
+ if (needs_free) {
296
+ Efree(Buffer);
297
298
return NULL;
299
} else {
300
DoError(ILLEGALFLOAT, "Illegal float specification");
0 commit comments