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

@ -36,8 +36,9 @@ OPCODE * avr_new_opcode(void)
m = (OPCODE *)malloc(sizeof(*m));
if (m == NULL) {
avrdude_message(MSG_INFO, "avr_new_opcode(): out of memory\n");
exit(1);
// avrdude_message(MSG_INFO, "avr_new_opcode(): out of memory\n");
// exit(1);
avrdude_oom("avr_new_opcode(): out of memory\n");
}
memset(m, 0, sizeof(*m));
@ -56,8 +57,9 @@ static OPCODE * avr_dup_opcode(OPCODE * op)
m = (OPCODE *)malloc(sizeof(*m));
if (m == NULL) {
avrdude_message(MSG_INFO, "avr_dup_opcode(): out of memory\n");
exit(1);
// avrdude_message(MSG_INFO, "avr_dup_opcode(): out of memory\n");
// exit(1);
avrdude_oom("avr_dup_opcode(): out of memory\n");
}
memcpy(m, op, sizeof(*m));
@ -249,8 +251,9 @@ AVRMEM * avr_new_memtype(void)
m = (AVRMEM *)malloc(sizeof(*m));
if (m == NULL) {
avrdude_message(MSG_INFO, "avr_new_memtype(): out of memory\n");
exit(1);
// avrdude_message(MSG_INFO, "avr_new_memtype(): out of memory\n");
// exit(1);
avrdude_oom("avr_new_memtype(): out of memory\n");
}
memset(m, 0, sizeof(*m));
@ -300,9 +303,10 @@ AVRMEM * avr_dup_mem(AVRMEM * m)
if (m->buf != NULL) {
n->buf = (unsigned char *)malloc(n->size);
if (n->buf == NULL) {
avrdude_message(MSG_INFO, "avr_dup_mem(): out of memory (memsize=%d)\n",
n->size);
exit(1);
// avrdude_message(MSG_INFO, "avr_dup_mem(): out of memory (memsize=%d)\n",
// n->size);
// exit(1);
avrdude_oom("avr_dup_mem(): out of memory");
}
memcpy(n->buf, m->buf, n->size);
}
@ -310,9 +314,10 @@ AVRMEM * avr_dup_mem(AVRMEM * m)
if (m->tags != NULL) {
n->tags = (unsigned char *)malloc(n->size);
if (n->tags == NULL) {
avrdude_message(MSG_INFO, "avr_dup_mem(): out of memory (memsize=%d)\n",
n->size);
exit(1);
// avrdude_message(MSG_INFO, "avr_dup_mem(): out of memory (memsize=%d)\n",
// n->size);
// exit(1);
avrdude_oom("avr_dup_mem(): out of memory");
}
memcpy(n->tags, m->tags, n->size);
}
@ -441,8 +446,9 @@ AVRPART * avr_new_part(void)
p = (AVRPART *)malloc(sizeof(AVRPART));
if (p == NULL) {
avrdude_message(MSG_INFO, "new_part(): out of memory\n");
exit(1);
// avrdude_message(MSG_INFO, "new_part(): out of memory\n");
// exit(1);
avrdude_oom("new_part(): out of memory\n");
}
memset(p, 0, sizeof(*p));