summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2015-04-18 11:49:04 +0200
committerLeo C2015-04-18 11:49:04 +0200
commitae017d4ce71be2ca45891ff6709f74f4fc963644 (patch)
tree653f3a9eab38dc281262fbfd43b517567c4afde4
parent179bc6099854fc3772517d781052b0d9aabc7329 (diff)
downloadz180-stamp-ae017d4ce71be2ca45891ff6709f74f4fc963644.zip
ihex.c fix memory alloc
-rw-r--r--avr/ihex.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/avr/ihex.c b/avr/ihex.c
index 2a9f033..4e7b1a8 100644
--- a/avr/ihex.c
+++ b/avr/ihex.c
@@ -90,25 +90,34 @@ ihex_t ihex_get_record() {
uint8_t *p; int k;
if ((rec.data = malloc(rec.len)) == 0)
return rec;
+
for (p=rec.data, k=rec.len; k; k--) {
if ((i = get_hexbyte()) < 0)
break;
sum += i;
*p++ = i;
}
+
if (k) {
free(rec.data); rec.data = 0;
return rec;
}
}
- if ((i = get_hexbyte()) < 0) /* Check sum */
- return rec;
- sum += i;
- if (sum) {
- free(rec.data); rec.data = 0;
- rec.status = IHX_CHKSUMERR;
- } else
- rec.status = IHX_OK;
+
+ i = get_hexbyte(); /* Check sum */
+
+ if (i >= 0) {
+ sum += i;
+ if (sum == 0)
+ rec.status = IHX_OK;
+ else
+ rec.status = IHX_CHKSUMERR;
+ }
+
+ if (rec.status != IHX_OK) {
+ free(rec.data);
+ rec.data = 0;
+ }
return rec;
}
@@ -176,6 +185,10 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp, int flag, int argc, char * const arg
} else
done = true;
+
+ free(rec.data);
+ rec.data = 0;
+
}
switch (rec.status) {