[flashrom] [commit] r1800 - trunk
repository service
svn at flashrom.org
Tue May 27 02:06:14 CEST 2014
Author: stefanct
Date: Tue May 27 02:06:14 2014
New Revision: 1800
URL: http://flashrom.org/trac/flashrom/changeset/1800
Log:
Fix various tiny problems in verify_range().
First of all, fix CID1130010: Resource leak as reported by Stefan Reinauer.
Alternatively to Stefan's approach, just move the malloc() out of the scope.
Additionally, get rid of an unnecessary exit(1) and correctly return -1 in all
error cases as documented.
Signed-off-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>
Acked-by: Stefan Tauner <stefan.tauner at alumni.tuwien.ac.at>
Modified:
trunk/flashrom.c
Modified: trunk/flashrom.c
==============================================================================
--- trunk/flashrom.c Tue May 27 00:05:31 2014 (r1799)
+++ trunk/flashrom.c Tue May 27 02:06:14 2014 (r1800)
@@ -672,20 +672,20 @@
*/
int verify_range(struct flashctx *flash, const uint8_t *cmpbuf, unsigned int start, unsigned int len)
{
- uint8_t *readbuf = malloc(len);
- int ret = 0;
-
if (!len)
- goto out_free;
+ return -1;
if (!flash->chip->read) {
msg_cerr("ERROR: flashrom has no read function for this flash chip.\n");
- return 1;
+ return -1;
}
+
+ uint8_t *readbuf = malloc(len);
if (!readbuf) {
msg_gerr("Could not allocate memory!\n");
- exit(1);
+ return -1;
}
+ int ret = 0;
if (start + len > flash->chip->total_size * 1024) {
msg_gerr("Error: %s called with start 0x%x + len 0x%x >"
@@ -699,7 +699,8 @@
if (ret) {
msg_gerr("Verification impossible because read failed "
"at 0x%x (len 0x%x)\n", start, len);
- return ret;
+ ret = -1;
+ goto out_free;
}
ret = compare_range(cmpbuf, readbuf, start, len);
More information about the flashrom
mailing list