[PATCH v1] gstreamer: Fix string memory leak

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue May 14 20:50:48 CEST 2024


Hi Barnabás,

Thank you for the patch.

On Tue, May 14, 2024 at 05:45:39PM +0000, Barnabás Pőcze wrote:
> The string returned by `gst_video_colorimetry_to_string()`
> has to be freed,

This is right.

> this was missing.

But are you sure about this ? The allocated colorimetry_str is passed to
gst_structure_set(), which I *think* doesn't copy the string but takes
ownership of it.

> Fixes: fc9783acc6083a ("gstreamer: Provide colorimetry <> ColorSpace mappings")
> Signed-off-by: Barnabás Pőcze <pobrn at protonmail.com>
> ---
>  src/gstreamer/gstlibcamera-utils.cpp | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp
> index e163ce41..ec4da435 100644
> --- a/src/gstreamer/gstlibcamera-utils.cpp
> +++ b/src/gstreamer/gstlibcamera-utils.cpp
> @@ -385,7 +385,7 @@ gst_libcamera_stream_configuration_to_caps(const StreamConfiguration &stream_cfg
>  
>  	if (stream_cfg.colorSpace) {
>  		GstVideoColorimetry colorimetry = colorimetry_from_colorspace(stream_cfg.colorSpace.value());
> -		gchar *colorimetry_str = gst_video_colorimetry_to_string(&colorimetry);
> +		g_autofree gchar *colorimetry_str = gst_video_colorimetry_to_string(&colorimetry);
>  
>  		if (colorimetry_str)
>  			gst_structure_set(s, "colorimetry", G_TYPE_STRING, colorimetry_str, nullptr);

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list