Firmware updater: Fix a race condition

avrdude: Handle OOM with configurable handler
This commit is contained in:
Vojtech Kral
2018-08-07 11:28:39 +02:00
committed by bubnikv
parent bd667aad6e
commit 60a0375ff9
14 changed files with 193 additions and 67 deletions

View File

@@ -38,8 +38,9 @@ UPDATE * parse_op(char * s)
upd = (UPDATE *)malloc(sizeof(UPDATE));
if (upd == NULL) {
avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
exit(1);
// avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
// exit(1);
avrdude_oom("parse_op: out of memory\n");
}
i = 0;
@@ -53,8 +54,9 @@ UPDATE * parse_op(char * s)
upd->op = DEVICE_WRITE;
upd->filename = (char *)malloc(strlen(buf) + 1);
if (upd->filename == NULL) {
avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
exit(1);
// avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
// exit(1);
avrdude_oom("parse_op: out of memory\n");
}
strcpy(upd->filename, buf);
upd->format = FMT_AUTO;
@@ -63,8 +65,9 @@ UPDATE * parse_op(char * s)
upd->memtype = (char *)malloc(strlen(buf)+1);
if (upd->memtype == NULL) {
avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
exit(1);
// avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
// exit(1);
avrdude_oom("parse_op: out of memory\n");
}
strcpy(upd->memtype, buf);
@@ -179,8 +182,9 @@ UPDATE * dup_update(UPDATE * upd)
u = (UPDATE *)malloc(sizeof(UPDATE));
if (u == NULL) {
avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
exit(1);
// avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
// exit(1);
avrdude_oom("dup_update: out of memory\n");
}
memcpy(u, upd, sizeof(UPDATE));
@@ -200,8 +204,9 @@ UPDATE * new_update(int op, char * memtype, int filefmt, char * filename, unsign
u = (UPDATE *)malloc(sizeof(UPDATE));
if (u == NULL) {
avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
exit(1);
// avrdude_message(MSG_INFO, "%s: out of memory\n", progname);
// exit(1);
avrdude_oom("new_update: out of memory\n");
}
u->memtype = strdup(memtype);