diff --git a/eeshow/lib-parse.c b/eeshow/lib-parse.c index 3dde578..93ef2d7 100644 --- a/eeshow/lib-parse.c +++ b/eeshow/lib-parse.c @@ -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); + } +} diff --git a/eeshow/lib.h b/eeshow/lib.h index 4bd4029..22f8720 100644 --- a/eeshow/lib.h +++ b/eeshow/lib.h @@ -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 */ diff --git a/eeshow/main.c b/eeshow/main.c index 02e9526..a29d97e 100644 --- a/eeshow/main.c +++ b/eeshow/main.c @@ -212,6 +212,7 @@ found: gfx_end(); sch_free(&sch_ctx); + lib_free(&lib); return 0; }