Skip to content

Commit

Permalink
Handle nullptr on malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
malleoz committed Sep 27, 2020
1 parent 8e8449a commit e710b0f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions FTPManagement.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ void handle_post(char* url, FILE *fp, int localRecord, char *nickname) {
long fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
wt.data = malloc(fsize+ strlen(nickname) + 49); // Offer enough padding for postfields

if (wt.data == NULL) {
printf("Fatal error! Ran out of heap memory.\n");
printf("Press enter to quit.");
char exitChar = getchar();
exit(1);
}

size_t bytes_written;
bytes_written = sprintf(wt.data, "{\"frames\":\"%d\",\"userName\":\"%s\",\"routeContent\":\"", localRecord, nickname);
fread(wt.data + bytes_written, 1, fsize, fp);
Expand Down

0 comments on commit e710b0f

Please sign in to comment.