output/text: Fix memory leak of internal state buffers.
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.
This commit is contained in:
parent
61bab807f4
commit
8c273ac57c
|
@ -133,4 +133,5 @@ SR_PRIV struct sr_output_format output_text_ascii = {
|
|||
.init = init_ascii,
|
||||
.data = data_ascii,
|
||||
.event = event,
|
||||
.cleanup = text_cleanup,
|
||||
};
|
||||
|
|
|
@ -116,4 +116,5 @@ SR_PRIV struct sr_output_format output_text_bits = {
|
|||
.init = init_bits,
|
||||
.data = data_bits,
|
||||
.event = event,
|
||||
.cleanup = text_cleanup,
|
||||
};
|
||||
|
|
|
@ -109,4 +109,5 @@ SR_PRIV struct sr_output_format output_text_hex = {
|
|||
.init = init_hex,
|
||||
.data = data_hex,
|
||||
.event = event,
|
||||
.cleanup = text_cleanup,
|
||||
};
|
||||
|
|
|
@ -171,6 +171,31 @@ err:
|
|||
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)
|
||||
{
|
||||
|
@ -195,8 +220,6 @@ SR_PRIV int event(struct sr_output *o, int event_type, uint8_t **data_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;
|
||||
|
|
|
@ -48,6 +48,7 @@ struct context {
|
|||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue