1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 12:32:24 +02:00

eeshow/lib-parse.c (lib_free): add cleanup of component data

This commit is contained in:
Werner Almesberger 2016-08-05 20:34:15 -03:00
parent c54bf3de06
commit 59b7946a5f
3 changed files with 38 additions and 0 deletions

View File

@ -268,3 +268,39 @@ void lib_init(struct lib *lib)
lib->comps = NULL;
lib->next_comp = &lib->comps;
}
static void free_objs(struct lib_obj *objs)
{
struct lib_obj *next;
while (objs) {
next = objs->next;
switch (objs->type) {
case lib_obj_text:
free((char *) objs->u.text.s);
break;
case lib_obj_pin:
free((char *) objs->u.pin.name);
free((char *) objs->u.pin.number);
break;
default:
break;
}
free(objs);
objs = next;
}
}
void lib_free(struct lib *lib)
{
struct comp *comp, *next;
for (comp = lib->comps; comp; comp = next) {
next = comp->next;
free((char *) comp->name);
free_objs(comp->objs);
free(comp);
}
}

View File

@ -121,5 +121,6 @@ void lib_render(const struct comp *comp, unsigned unit, const int m[6]);
void lib_parse(struct lib *lib, const char *name, const struct file *related);
void lib_init(struct lib *lib);
void lib_free(struct lib *lib);
#endif /* !LIB_H */

View File

@ -212,6 +212,7 @@ found:
gfx_end();
sch_free(&sch_ctx);
lib_free(&lib);
return 0;
}