Skip to content

Commit

Permalink
Fix free-before-use error
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Feb 27, 2016
1 parent f7f4719 commit b56cb4c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions espcomm/espcomm.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,20 +529,22 @@ bool espcomm_upload_file(const char *name)

size_t cb = fread(file_contents, 1, st.st_size, f);
fclose(f);
free(file_contents);

if (cb != st.st_size)
{
LOGERR("failed to read file contents");
free(file_contents);
return false;
}

if (!espcomm_upload_mem(file_contents, st.st_size))
{
LOGERR("espcomm_upload_mem failed");
free(file_contents);
return false;
}

free(file_contents);
return true;
}

Expand Down Expand Up @@ -671,4 +673,4 @@ bool espcomm_erase_flash()
send_packet.checksum = 0;
espcomm_send_command(RAM_DOWNLOAD_END, (unsigned char*) ram_packet, 8, 0);
return true;
}
}

0 comments on commit b56cb4c

Please sign in to comment.