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.
diff --git a/src/sample.c b/src/sample.c
index 68b52ac..2e22104 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -1452,7 +1452,7 @@
if (!buf)
goto end;
- sink = (struct sink *)arg_p[1].data.str.area;
+ sink = (struct sink *)arg_p[1].data.ptr;
BUG_ON(!sink);
pfx = arg_p[0].data.str.area;
@@ -1514,8 +1514,8 @@
return 0;
}
- args[1].data.str.area = (char *)sink;
- args[1].data.str.data = 0; // that's not a string anymore
+ args[1].type = ARGT_PTR;
+ args[1].data.ptr = sink;
return 1;
}