Free memory allocated in asn1c_compiled_output() and asn1c_lang_C_type_SEx_OF_def()
diff --git a/libasn1compiler/asn1c_C.c b/libasn1compiler/asn1c_C.c
index dc74bc8..246dd66 100644
--- a/libasn1compiler/asn1c_C.c
+++ b/libasn1compiler/asn1c_C.c
@@ -813,6 +813,8 @@
arg->embed++;
emit_member_table(arg, v);
arg->embed--;
+ free(v->Identifier);
+ v->Identifier = (char *)NULL;
INDENT(-1);
OUT("};\n");
diff --git a/libasn1compiler/asn1compiler.c b/libasn1compiler/asn1compiler.c
index 18b2c00..42d55e6 100644
--- a/libasn1compiler/asn1compiler.c
+++ b/libasn1compiler/asn1compiler.c
@@ -6,6 +6,7 @@
static void default_logger_cb(int, const char *fmt, ...);
static int asn1c_compile_expr(arg_t *arg);
static int asn1c_attach_streams(asn1p_expr_t *expr);
+static int asn1c_detach_streams(asn1p_expr_t *expr);
int
asn1_compile(asn1p_t *asn, const char *datadir, enum asn1c_flags flags,
@@ -61,6 +62,12 @@
if(asn1c_save_compiled_output(arg, datadir, argc, optc, argv))
return -1;
+ TQ_FOR(mod, &(asn->modules), mod_next) {
+ TQ_FOR(arg->expr, &(mod->members), next) {
+ asn1c_detach_streams(arg->expr);
+ }
+ }
+
return 0;
}
@@ -159,6 +166,28 @@
return 0;
}
+int
+asn1c_detach_streams(asn1p_expr_t *expr) {
+ compiler_streams_t *cs;
+ out_chunk_t *m;
+ int i;
+
+ if(!expr->data)
+ return 0; /* Already detached? */
+
+ cs = expr->data;
+ for(i = 0; i < OT_MAX; i++) {
+ while((m = TQ_REMOVE(&(cs->destination[i].chunks), next))) {
+ free(m->buf);
+ free(m);
+ }
+ }
+ free(expr->data);
+ expr->data = (void *)NULL;
+
+ return 0;
+}
+
static void
default_logger_cb(int _severity, const char *fmt, ...) {
va_list ap;