[{"id":32988,"web_url":"https://patchwork.libcamera.org/comment/32988/","msgid":"<173644507162.3771432.5024922714007010879@ping.linuxembedded.co.uk>","date":"2025-01-09T17:51:11","subject":"Re: [PATCH v3 2/2] gstreamer: allocator:\n\tgst_libcamera_allocator_new(): Fix memory leak","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Barnabás Pőcze (2025-01-06 10:06:22)\n> If `FrameBufferAllocator::allocate()` causes the construction to be\n> aborted, the allocated `GstLibcameraAllocator` will not be\n> deallocated properly. Use `g_autoptr()` to address this.\n> \n> `g_steal_pointer()` could only be used in glib 2.68 or later because\n> earlier it evaluates to a pointer-to-void in C++, which would necessitate\n> a `static_cast`.\n> \n> Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nThis looks ok to me, but I suspect Nicolas' review is more valuable than\nmine on this one.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> Changes in v3:\n>   - fix #include order\n> \n> Changes in v2:\n>   - add `#include <utility>`\n> ---\n>  src/gstreamer/gstlibcameraallocator.cpp | 12 ++++++------\n>  1 file changed, 6 insertions(+), 6 deletions(-)\n> \n> diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> index b0c84893a..d4492d994 100644\n> --- a/src/gstreamer/gstlibcameraallocator.cpp\n> +++ b/src/gstreamer/gstlibcameraallocator.cpp\n> @@ -8,6 +8,8 @@\n> \n>  #include \"gstlibcameraallocator.h\"\n> \n> +#include <utility>\n> +\n>  #include <libcamera/camera.h>\n>  #include <libcamera/framebuffer_allocator.h>\n>  #include <libcamera/stream.h>\n> @@ -199,15 +201,13 @@ GstLibcameraAllocator *\n>  gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,\n>                             CameraConfiguration *config_)\n>  {\n> -       auto *self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,\n> -                                                         nullptr));\n> +       g_autoptr(GstLibcameraAllocator) self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,\n> +                                                                                    nullptr));\n>         gint ret;\n> \n>         self->cm_ptr = new std::shared_ptr<CameraManager>(gst_libcamera_get_camera_manager(ret));\n> -       if (ret) {\n> -               g_object_unref(self);\n> +       if (ret)\n>                 return nullptr;\n> -       }\n> \n>         self->fb_allocator = new FrameBufferAllocator(camera);\n>         for (StreamConfiguration &streamCfg : *config_) {\n> @@ -228,7 +228,7 @@ gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,\n>                 g_hash_table_insert(self->pools, stream, pool);\n>         }\n> \n> -       return self;\n> +       return std::exchange(self, nullptr);\n>  }\n> \n>  bool\n> --\n> 2.47.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id EB2EAC32EF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jan 2025 17:51:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 160E061880;\n\tThu,  9 Jan 2025 18:51:17 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9458061880\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jan 2025 18:51:14 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 87F789FC;\n\tThu,  9 Jan 2025 18:50:20 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"NHvNc/qs\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1736445020;\n\tbh=Db8cF3kW9DPRTyCeTwYXni2QJS5rsNjNuTzCw5Jk5f0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=NHvNc/qsE4ODGkVQEjd5o8G0Ob75eIU/JdjfIPNS8U1Sy0ybn6dBPkEfVrAvVxyyl\n\ta3YaNJBJ+BmXbEuZy7q88navobg/LDldODr8k8wmrxwkEo7YDn29XpYTpqs7WOuiQ0\n\tmcjUwpqL3Vbe+KU4JDyObVJMrDwPLlhVmHvJ8OWQ=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250106100613.493108-2-pobrn@protonmail.com>","References":"<20250106100613.493108-1-pobrn@protonmail.com>\n\t<20250106100613.493108-2-pobrn@protonmail.com>","Subject":"Re: [PATCH v3 2/2] gstreamer: allocator:\n\tgst_libcamera_allocator_new(): Fix memory leak","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Thu, 09 Jan 2025 17:51:11 +0000","Message-ID":"<173644507162.3771432.5024922714007010879@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":32990,"web_url":"https://patchwork.libcamera.org/comment/32990/","msgid":"<4a5c9b74e82ff04eed21009d20689a9fdea15986.camel@ndufresne.ca>","date":"2025-01-09T20:03:15","subject":"Re: [PATCH v3 2/2] gstreamer: allocator:\n\tgst_libcamera_allocator_new(): Fix memory leak","submitter":{"id":30,"url":"https://patchwork.libcamera.org/api/people/30/","name":"Nicolas Dufresne","email":"nicolas@ndufresne.ca"},"content":"Hey,\n\nLe jeudi 09 janvier 2025 à 17:51 +0000, Kieran Bingham a écrit :\n> Quoting Barnabás Pőcze (2025-01-06 10:06:22)\n> > If `FrameBufferAllocator::allocate()` causes the construction to be\n> > aborted, the allocated `GstLibcameraAllocator` will not be\n> > deallocated properly. Use `g_autoptr()` to address this.\n> > \n> > `g_steal_pointer()` could only be used in glib 2.68 or later because\n> > earlier it evaluates to a pointer-to-void in C++, which would necessitate\n> > a `static_cast`.\n> > \n> > Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>\n> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> This looks ok to me, but I suspect Nicolas' review is more valuable than\n> mine on this one.\n> \n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\nWell, as requested:\n\nReviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>\n\n> \n> > ---\n> > Changes in v3:\n> >   - fix #include order\n> > \n> > Changes in v2:\n> >   - add `#include <utility>`\n> > ---\n> >  src/gstreamer/gstlibcameraallocator.cpp | 12 ++++++------\n> >  1 file changed, 6 insertions(+), 6 deletions(-)\n> > \n> > diff --git a/src/gstreamer/gstlibcameraallocator.cpp b/src/gstreamer/gstlibcameraallocator.cpp\n> > index b0c84893a..d4492d994 100644\n> > --- a/src/gstreamer/gstlibcameraallocator.cpp\n> > +++ b/src/gstreamer/gstlibcameraallocator.cpp\n> > @@ -8,6 +8,8 @@\n> > \n> >  #include \"gstlibcameraallocator.h\"\n> > \n> > +#include <utility>\n> > +\n> >  #include <libcamera/camera.h>\n> >  #include <libcamera/framebuffer_allocator.h>\n> >  #include <libcamera/stream.h>\n> > @@ -199,15 +201,13 @@ GstLibcameraAllocator *\n> >  gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,\n> >                             CameraConfiguration *config_)\n> >  {\n> > -       auto *self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,\n> > -                                                         nullptr));\n> > +       g_autoptr(GstLibcameraAllocator) self = GST_LIBCAMERA_ALLOCATOR(g_object_new(GST_TYPE_LIBCAMERA_ALLOCATOR,\n> > +                                                                                    nullptr));\n> >         gint ret;\n> > \n> >         self->cm_ptr = new std::shared_ptr<CameraManager>(gst_libcamera_get_camera_manager(ret));\n> > -       if (ret) {\n> > -               g_object_unref(self);\n> > +       if (ret)\n> >                 return nullptr;\n> > -       }\n> > \n> >         self->fb_allocator = new FrameBufferAllocator(camera);\n> >         for (StreamConfiguration &streamCfg : *config_) {\n> > @@ -228,7 +228,7 @@ gst_libcamera_allocator_new(std::shared_ptr<Camera> camera,\n> >                 g_hash_table_insert(self->pools, stream, pool);\n> >         }\n> > \n> > -       return self;\n> > +       return std::exchange(self, nullptr);\n> >  }\n> > \n> >  bool\n> > --\n> > 2.47.1\n> >","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8D894C32EF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  9 Jan 2025 20:03:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AB780684EA;\n\tThu,  9 Jan 2025 21:03:19 +0100 (CET)","from mail-qk1-x733.google.com (mail-qk1-x733.google.com\n\t[IPv6:2607:f8b0:4864:20::733])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id C7DDD61880\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  9 Jan 2025 21:03:17 +0100 (CET)","by mail-qk1-x733.google.com with SMTP id\n\taf79cd13be357-7b6c3629816so74925185a.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 09 Jan 2025 12:03:17 -0800 (PST)","from nicolas-tpx395.localdomain ([2606:6d00:15:862e::7a9])\n\tby smtp.gmail.com with ESMTPSA id\n\t6a1803df08f44-6dfade8a5d6sm1673676d6.109.2025.01.09.12.03.15\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 09 Jan 2025 12:03:16 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=ndufresne-ca.20230601.gappssmtp.com\n\theader.i=@ndufresne-ca.20230601.gappssmtp.com\n\theader.b=\"aWXI+dfE\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ndufresne-ca.20230601.gappssmtp.com; s=20230601; t=1736452997;\n\tx=1737057797; darn=lists.libcamera.org; \n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject\n\t:date:message-id:reply-to;\n\tbh=u5Vwz25VT8ooFRYMmA6FGm0y2ng3d5J+r5Jile6RjUA=;\n\tb=aWXI+dfExfI9IM/+gfZRcBUvJrzbBo4RYrSqHQtoMsBkIWnhvIqKNGTB5tQPRpmHFD\n\t1QtgPtm3TOnv4HPghnsT5W2G2sUrUXviBZc3UtvnQ2STEage++sM33oNH1sn1sz1Z/ET\n\ti+frZqPNZSTBQKsOgTdnJvHxGgPNvADZVjTFnMmjxJzuxZW1N+RkfXiwnvHWJuHKa1FY\n\tYfHsXJN/yXV6iPXKr4LVeeXDyS9NdzPQBFGM9ribfQToQdQHW8ws4dLxVvJe8v/0PzwT\n\t8j/QzBMIlBy8lvMHuAkPpAL0I4RYTFIFRe6aaEkpEXUnW+dKe45J2ZIQv1igJEnEZlvy\n\tC20Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1736452997; x=1737057797;\n\th=mime-version:user-agent:content-transfer-encoding:references\n\t:in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=u5Vwz25VT8ooFRYMmA6FGm0y2ng3d5J+r5Jile6RjUA=;\n\tb=PQ8W0uTgki/koDHIkzA6m3z3PlavqNoCR48l+Hi44vcCyCsP4U+9SKIsp9ppmyv0s/\n\tdykG/9TnkVA5nlhTKiCzP/IA4I6EdZ2aUs5hwXT7ZLsKz5aDxnzlfu/9vUE52jBkqkwY\n\trCeWjPrR7YqYVZZwjHqE2qWw5O0qow6WOS482hljy16TTinNolAIPoYV4Aq4jEEcbIgf\n\tUUn/EuAmvhzlay/Um4k2fkOj7pfRjpiqbBZGHzv2ekCE2ZnrJ8HkYYDiXV12RKSyVUlI\n\tFkiBvveD822jxviBsjqDJJ8IY3yGcye++fiw6hFs8Yfa19tyRezdUp1NOuwLvIq0A1F5\n\tD1/w==","X-Forwarded-Encrypted":"i=1;\n\tAJvYcCWRtVe0AKbCA8hvPiNUjHG1NdNH4fLbVG7DohqoX2d40mmUSBBmm8Gcs+QZeWe+c1BmdoAJsDCVEw1jCWE7jo0=@lists.libcamera.org","X-Gm-Message-State":"AOJu0Yy65pzsezOEWge5Ehis2bDQk0cF3i3yQXIntHTUxytf7A99pHMU\n\tb7Tyc6DzhRuhJxw+fD/UKHAvMbpTjHUA+3tz597VuJDtmoSfBgy4lkKuqRU3WxCUxou+BIXsvKt\n\twLTM=","X-Gm-Gg":"ASbGnctWB6sYR/vK0ATuMsV/lHi8LcqTw6w7FkXm+avagRbJCLCQJFli99I7veDdaJ2\n\tHmg/AmAnYCFUaA63uQtWEwX1iPkRhaBloo55SywEJ7trIJxU8arK1iibJjDqkk0bikefZ+a1zNM\n\tQr6Brdwo3YK+1mvTwP8lt9r5UVNToHxLuVfYBbeqoFaNjtV+T56W6KDp9VGMaXLPJ86OEm3MiZC\n\t1/1dz6pdrtR7OuoU5Aw4RoXs/SRRs3qbrlKuzs6VHrGRyKh8Hx++4tESw==","X-Google-Smtp-Source":"AGHT+IFyOlL2hUc+oa90fMTwIU5mqO4e/KJt4gh0FEi11Ro4p12wIC4ee5lO8RncecZHlz8XUc47dA==","X-Received":"by 2002:a05:6214:240d:b0:6da:da7b:c196 with SMTP id\n\t6a1803df08f44-6df9b1ef794mr146285906d6.16.1736452996705; \n\tThu, 09 Jan 2025 12:03:16 -0800 (PST)","Message-ID":"<4a5c9b74e82ff04eed21009d20689a9fdea15986.camel@ndufresne.ca>","Subject":"Re: [PATCH v3 2/2] gstreamer: allocator:\n\tgst_libcamera_allocator_new(): Fix memory leak","From":"Nicolas Dufresne <nicolas@ndufresne.ca>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>, =?utf-8?q?Barnab?=\n\t=?utf-8?b?w6FzIFDFkWN6ZQ==?= <pobrn@protonmail.com>,\n\tlibcamera-devel@lists.libcamera.org","Cc":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Date":"Thu, 09 Jan 2025 15:03:15 -0500","In-Reply-To":"<173644507162.3771432.5024922714007010879@ping.linuxembedded.co.uk>","References":"<20250106100613.493108-1-pobrn@protonmail.com>\n\t<20250106100613.493108-2-pobrn@protonmail.com>\n\t<173644507162.3771432.5024922714007010879@ping.linuxembedded.co.uk>","Content-Type":"text/plain; charset=\"UTF-8\"","Content-Transfer-Encoding":"quoted-printable","User-Agent":"Evolution 3.54.2 (3.54.2-1.fc41) ","MIME-Version":"1.0","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]