The text output module keeps buffers for internal state, upon receiving a DF_END
packet it frees the internal context but the buffers are never freed.
This adds a text_cleanup() helper function and registers it as the cleanup
function within all the text output modules.
.init = init_ascii,
.data = data_ascii,
.event = event,
+ .cleanup = text_cleanup,
};
.init = init_bits,
.data = data_bits,
.event = event,
+ .cleanup = text_cleanup,
};
.init = init_hex,
.data = data_hex,
.event = event,
+ .cleanup = text_cleanup,
};
return ret;
}
+SR_PRIV int text_cleanup(struct sr_output *o)
+{
+ struct context *ctx;
+
+ if (!o)
+ return SR_ERR_ARG;
+
+ ctx = o->internal;
+
+ g_free(ctx->header);
+ g_free(ctx->linebuf);
+ g_free(ctx->linevalues);
+
+ if (ctx->prevsample)
+ g_free(ctx->prevsample);
+
+ g_slist_free(ctx->probenames);
+
+ g_free(ctx);
+
+ o->internal = NULL;
+
+ return SR_OK;
+}
+
SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out,
uint64_t *length_out)
{
flush_linebufs(ctx, outbuf);
*data_out = outbuf;
*length_out = strlen((const char *)outbuf);
- g_free(o->internal);
- o->internal = NULL;
break;
default:
*data_out = NULL;
SR_PRIV void flush_linebufs(struct context *ctx, uint8_t *outbuf);
SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode);
+SR_PRIV int text_cleanup(struct sr_output *o);
SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_out,
uint64_t *length_out);