Skip to content

Commit f37ffb7

Browse files
author
s.hasert
committed
Check success of mallocs + assign buf to NULL after free + moved free of buf under loop
- `malloc()` now gets checked for success. If they fail we goto cleanup. - `buf` now gets assigned to `NULL` after being freed. - `free()` of `buf` got moved immediately under loop that uses it.
1 parent 3e89c13 commit f37ffb7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ltsmc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ int main(int argc, char *argv[])
494494
}
495495

496496
char* buf = malloc(TSM_BUF_LENGTH);
497+
if (!buf) {
498+
goto cleanup_tsm;
499+
}
500+
497501
size_t size;
498502
do {
499503
size = fread(buf, 1, TSM_BUF_LENGTH, stdin);
@@ -511,16 +515,16 @@ int main(int argc, char *argv[])
511515
}
512516
} while (!feof(stdin));
513517

518+
if (buf) free(buf);
519+
buf = NULL;
520+
514521
rc = tsm_fclose(&session);
515522
if (rc)
516523
CT_ERROR(errno, "tsm_fclose failed");
517524

518-
free(buf);
519-
520525
goto cleanup_tsm;
521526
}
522527

523-
524528
session.progress = progress_callback;
525529

526530
rc = tsm_connect(&login, &session);

0 commit comments

Comments
 (0)