bug #34302: Feature request : device configuration with parent classes

(not in original patch) 
* avrpart.c: New function avr_dup_opcode. avr_dup_mem/avr_dup_part-
	functions now duplicate the opcodes in their op-array to avoid memory leaks.
* doc/avrdude.texi: Added description of part parent f

git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1028 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Rene Liebscher
2011-12-29 16:51:44 +00:00
parent 64b32eb829
commit 7b66c21c05
6 changed files with 141 additions and 48 deletions

View File

@@ -47,6 +47,26 @@ OPCODE * avr_new_opcode(void)
return m;
}
static OPCODE * avr_dup_opcode(OPCODE * op)
{
OPCODE * m;
/* this makes life easier */
if (op == NULL) {
return NULL;
}
m = (OPCODE *)malloc(sizeof(*m));
if (m == NULL) {
fprintf(stderr, "avr_dup_opcode(): out of memory\n");
exit(1);
}
memcpy(m, op, sizeof(*m));
return m;
}
/*
* avr_set_bits()
@@ -248,28 +268,37 @@ int avr_initmem(AVRPART * p)
AVRMEM * avr_dup_mem(AVRMEM * m)
{
AVRMEM * n;
int i;
n = avr_new_memtype();
*n = *m;
n->buf = (unsigned char *)malloc(n->size);
if (n->buf == NULL) {
fprintf(stderr,
"avr_dup_mem(): out of memory (memsize=%d)\n",
n->size);
exit(1);
if (m->buf != NULL) {
n->buf = (unsigned char *)malloc(n->size);
if (n->buf == NULL) {
fprintf(stderr,
"avr_dup_mem(): out of memory (memsize=%d)\n",
n->size);
exit(1);
}
memcpy(n->buf, m->buf, n->size);
}
memcpy(n->buf, m->buf, n->size);
n->tags = (unsigned char *)malloc(n->size);
if (n->tags == NULL) {
fprintf(stderr,
"avr_dup_mem(): out of memory (memsize=%d)\n",
n->size);
exit(1);
if (m->tags != NULL) {
n->tags = (unsigned char *)malloc(n->size);
if (n->tags == NULL) {
fprintf(stderr,
"avr_dup_mem(): out of memory (memsize=%d)\n",
n->size);
exit(1);
}
memcpy(n->tags, m->tags, n->size);
}
for (i = 0; i < AVR_OP_MAX; i++) {
n->op[i] = avr_dup_opcode(n->op[i]);
}
memcpy(n->tags, m->tags, n->size);
return n;
}
@@ -398,6 +427,7 @@ AVRPART * avr_dup_part(AVRPART * d)
AVRPART * p;
LISTID save;
LNODEID ln;
int i;
p = avr_new_part();
save = p->mem;
@@ -410,6 +440,10 @@ AVRPART * avr_dup_part(AVRPART * d)
ladd(p->mem, avr_dup_mem(ldata(ln)));
}
for (i = 0; i < AVR_OP_MAX; i++) {
p->op[i] = avr_dup_opcode(p->op[i]);
}
return p;
}