BUG/MINOR: converters: Store the sink in an arg pointer for debug() converter

The debug() converter uses a string to reference the sink where to send debug
events. During the configuration parsing, this string is converted to a sink
object but it is still store as a string argument. It is a problem on deinit
because string arguments are released. So the sink pointer will be released
twice.

To fix the bug, we keep a reference on the sink using an ARGT_PTR argument. This
way, it will not be freed on the deinit.

This patch depends on the commit e02fc4d0d ("MINOR: arg: Add an argument type to
keep a reference on opaque data"). Both must be backported as far as 2.1.
This commit is contained in:
Christopher Faulet 2020-08-07 14:00:23 +02:00
parent e02fc4d0dd
commit b45bf8eb70

View File

@ -1452,7 +1452,7 @@ static int sample_conv_debug(const struct arg *arg_p, struct sample *smp, void *
if (!buf) if (!buf)
goto end; goto end;
sink = (struct sink *)arg_p[1].data.str.area; sink = (struct sink *)arg_p[1].data.ptr;
BUG_ON(!sink); BUG_ON(!sink);
pfx = arg_p[0].data.str.area; pfx = arg_p[0].data.str.area;
@ -1514,8 +1514,8 @@ static int smp_check_debug(struct arg *args, struct sample_conv *conv,
return 0; return 0;
} }
args[1].data.str.area = (char *)sink; args[1].type = ARGT_PTR;
args[1].data.str.data = 0; // that's not a string anymore args[1].data.ptr = sink;
return 1; return 1;
} }