Skip to content

Commit

Permalink
Free allocated memory on error
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Mar 29, 2017
1 parent 58f667f commit 476453f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gammu/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,14 @@ void Screenshot(int argc UNUSED, char *argv[])
f = fopen(fname, "w");
if (f == NULL) {
printf_err("Failed to open file: %s\n", fname);
free(fname);
return;
}
written = fwrite(pic.Buffer, 1, pic.Length, f);
ret = fclose(f);
if (ret != 0 || written != pic.Length) {
printf_err("Failed to write file: %s\n", fname);
free(fname);
return;
}

Expand Down

0 comments on commit 476453f

Please sign in to comment.