From patchwork Tue Sep 21 17:39:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13879 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0EF9ABF01C for ; Tue, 21 Sep 2021 17:40:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 503266918C; Tue, 21 Sep 2021 19:40:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="J7c00G9k"; dkim-atps=neutral Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C91ED60247 for ; Tue, 21 Sep 2021 19:40:15 +0200 (CEST) Received: by mail-pf1-x42d.google.com with SMTP id w14so211962pfu.2 for ; Tue, 21 Sep 2021 10:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AjTUusiayGb8XNBYuRtkKRQ3PtUl1WcJg3+jWBjSajQ=; b=J7c00G9kQFqssmixNylVrlcnWDCBzlQpt59zi0Svb1b6BHKPDrbgLq2W/Fb1RZ1KET C0wbhLqGnnBlw9di+Hx3cl/8+brTQQhCtx37hNVTbDytI+dlJ5+WZK7bop+SyxMkL5JN QFHsgM9ThB/PRNNiI+cgvD5rpKGht4ZaqbR3gYFm5S2vcc1WiNMLo8u1LZHyW3sEJW9t 6G3mgBCt+Nh7aaodGsTacGvv3DR4nHzrTDGdaqdZ6NM0lk48iyftC2we3zSEiTOP3/Ib DjKn48ZqAFNnvbuMiduDYd6RXCG2jn3VT13n+7QPkzhLW+koqPxCQ8N981RikOP0Cy16 6elg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AjTUusiayGb8XNBYuRtkKRQ3PtUl1WcJg3+jWBjSajQ=; b=D0GUSKSRBhMR2zuFe6Etxth0XfSPlVul69k2OTotrv6xfhrcNRXayAuSL/RxMz0aHQ Xijv9u0d2cX+g3zSAetKzQ4zcxEjB3yAj1eomy/CmX9v5V7QJ2IBU3tQKAWvPiGhm2R2 h6gfg9ab3gHilxsQ1GkqZMC//IFCvrDD6YKNFtOebXzCSMG49OsUndK6AcDzqXUNC3il WRNL9mJaQwsKqSSHlacymus5J5zLw7jQeltLfhGMhH2cOhGd5OGD3Xq9ex299F3qg3T7 wao8jFrw9HEzq/Q7HwhAE2K8Idh15iodRAug12nqLi/w4jYrznk9/n1P5b0gYxuexZfs drmA== X-Gm-Message-State: AOAM531HrT/ilHtBAsfbU4Fk7JGYCEnSz9rMK3pf874kBTL9KTJAsvF6 HYkmFWEQ6SyOdp2hKgfuA2eZmAGCbBvU2gdX X-Google-Smtp-Source: ABdhPJzo0NTMaousF8N6WcsWTAjQ22RijK3BRoOsgfCTaKMaOqWmGlaSDKUWd0D4Y9IQIPom6wlVbA== X-Received: by 2002:a62:ce0d:0:b0:438:71f1:4442 with SMTP id y13-20020a62ce0d000000b0043871f14442mr32215187pfg.21.1632246013857; Tue, 21 Sep 2021 10:40:13 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.167]) by smtp.googlemail.com with ESMTPSA id k190sm19800772pgc.11.2021.09.21.10.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 10:40:13 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Sep 2021 23:09:53 +0530 Message-Id: <20210921173955.20408-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/3] test: gstreamer_single_stream_test: Fix memory leak X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicolas Dufresne , Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The test hold a valid reference to convert0_ and sink0_ but not released. This results in a memory leak and can be checked via valgrind. Drop the references with test cleanup() virtual function. Valgrind log (glib and gst suppression files were used): ==345380== LEAK SUMMARY: ==345380== definitely lost: 1,688 bytes in 2 blocks ==345380== indirectly lost: 7,069 bytes in 42 blocks The patch fixes the leaks reported by valgrind above to: ==348870== LEAK SUMMARY: ==348870== definitely lost: 0 bytes in 0 blocks ==348870== indirectly lost: 0 bytes in 0 blocks Signed-off-by: Vedant Paranjape Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne Reviewed-by: Paul Elder --- test/gstreamer/gstreamer_single_stream_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp index 7292f3280617..2b561d6bf9f2 100644 --- a/test/gstreamer/gstreamer_single_stream_test.cpp +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -72,6 +72,12 @@ protected: return TestPass; } + void cleanup() override + { + g_clear_object(&convert0_); + g_clear_object(&sink0_); + } + private: GstElement *convert0_; GstElement *sink0_; From patchwork Tue Sep 21 17:39:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13880 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 3AE04BF01C for ; Tue, 21 Sep 2021 17:40:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EF7BA6918F; Tue, 21 Sep 2021 19:40:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HdP6Wh5j"; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2DAE360247 for ; Tue, 21 Sep 2021 19:40:21 +0200 (CEST) Received: by mail-pf1-x430.google.com with SMTP id j6so200225pfa.4 for ; Tue, 21 Sep 2021 10:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tb4uXsSEYUVCuLNaLZVZWGtIEeTVTZs1So588/ItGS8=; b=HdP6Wh5jDsfb7R08nTVTSe4HEl0u/Ya3olPXo9enQ8UOJ6gXI2ev45uPe/LliHB9MU ksKOBfcNm/X2+L1nGLhNkQ/QR+po94gAkk1NhTObW3x/Io/3IYZQFQWMNhE2Iu8ngyWE 8btIO3za939/ZytIZtSNC7gpaKkC65TEAWTOFSIFJD/BDpSXvdKRbqPV632YdmpzODRw 2AbRxUXyvTDHTRBlUNq2fYLyx41rur1TvzVWTr/DpIlOeZ6sSVhOaNna06CBAx2+e7Yb K2sDSKAJmAxZ8mPENRuoD0ByQIgRymNHn0514bSZMruLOLGWd7ohJl3Pj6qnY/I7NuHR VBAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tb4uXsSEYUVCuLNaLZVZWGtIEeTVTZs1So588/ItGS8=; b=0zNLpFp2qVlnwNDlIqM+gs2WrKI+Fi+35Cy5Hk9UMYIpJeO0kPHz6AeMxKfE5z5NuE DAYkVKGlvAtHhGqLK4ODE+7H3A1fOU+FmrQNJCI3RcaoabmFXeGdvBIbBbgJGMNWz5Hs ZBZSwElNDLPPYqhF2RVrzLowuA/HiGsm4b1diAm5TVEAyhKN4D7JtAzKuqdEcyZCWmaM HWczxXbLPh2CCEV3DnUhUF0G/a8c8jkjoAnQ7Mf2M/pj/GdVLf9lVOe8V0LAayekAfIf SkGEToX/JwjwjyBU1uB33/o6jeQFLn5AjVEIM+eV8l8ilZxpHkawxmGpV9pO1Ro5jxJj LfyA== X-Gm-Message-State: AOAM533PPCpJ9iE1V2asr/1WocaYvIGWBGFFEG4iGhjgD874ZMOnVuA9 kdTvk894Dgxj8ZTXEM3lvMjjrQCITbi5PA== X-Google-Smtp-Source: ABdhPJwzns9XmSq/4v95jqJVXmSNdb2T4rFplPfpLnGpABWYBgpPJwgBXxf3rFbfkA5rM+z3jUh2QQ== X-Received: by 2002:a63:4464:: with SMTP id t36mr29431811pgk.4.1632246019530; Tue, 21 Sep 2021 10:40:19 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.167]) by smtp.googlemail.com with ESMTPSA id k190sm19800772pgc.11.2021.09.21.10.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 10:40:19 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Sep 2021 23:09:54 +0530 Message-Id: <20210921173955.20408-2-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210921173955.20408-1-vedantparanjape160201@gmail.com> References: <20210921173955.20408-1-vedantparanjape160201@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/3] test: gstreamer: Simplify single stream test using functions from GstUtils X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicolas Dufresne , Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Simplify memory handling and complexity of the test by using gst_parse_bin_from_description_full [1]. [1]: https://gstreamer.freedesktop.org/documentation/gstreamer/gstutils.html?gi-language=c#gst_parse_bin_from_description_full Signed-off-by: Vedant Paranjape Reviewed-by: Nicolas Dufresne Reviewed-by: Paul Elder --- .../gstreamer_single_stream_test.cpp | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp index 2b561d6bf9f2..bd74ada0e244 100644 --- a/test/gstreamer/gstreamer_single_stream_test.cpp +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -33,20 +33,18 @@ protected: if (status_ != TestPass) return status_; - g_autoptr(GstElement) convert0 = gst_element_factory_make("videoconvert", "convert0"); - g_autoptr(GstElement) sink0 = gst_element_factory_make("fakesink", "sink0"); - g_object_ref_sink(convert0); - g_object_ref_sink(sink0); - - if (!convert0 || !sink0) { - g_printerr("Not all elements could be created. %p.%p\n", - convert0, sink0); - + const gchar *streamDescription = "videoconvert ! fakesink"; + g_autoptr(GError) error0 = NULL; + stream0_ = gst_parse_bin_from_description_full(streamDescription, TRUE, + NULL, + GST_PARSE_FLAG_FATAL_ERRORS, + &error0); + + if (!stream0_) { + g_printerr("Bin could not be created (%s)\n", error0->message); return TestFail; } - - convert0_ = reinterpret_cast(g_steal_pointer(&convert0)); - sink0_ = reinterpret_cast(g_steal_pointer(&sink0)); + g_object_ref_sink(stream0_); if (createPipeline() != TestPass) return TestFail; @@ -57,8 +55,8 @@ protected: int run() override { /* Build the pipeline */ - gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, convert0_, sink0_, NULL); - if (gst_element_link_many(libcameraSrc_, convert0_, sink0_, NULL) != TRUE) { + gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, stream0_, NULL); + if (gst_element_link(libcameraSrc_, stream0_) != TRUE) { g_printerr("Elements could not be linked.\n"); return TestFail; } @@ -74,13 +72,11 @@ protected: void cleanup() override { - g_clear_object(&convert0_); - g_clear_object(&sink0_); + g_clear_object(&stream0_); } private: - GstElement *convert0_; - GstElement *sink0_; + GstElement *stream0_; }; TEST_REGISTER(GstreamerSingleStreamTest) From patchwork Tue Sep 21 17:39:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13881 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A5580BF01C for ; Tue, 21 Sep 2021 17:40:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 644D569191; Tue, 21 Sep 2021 19:40:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HrvX5kJs"; dkim-atps=neutral Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 564FB6918A for ; Tue, 21 Sep 2021 19:40:25 +0200 (CEST) Received: by mail-pf1-x434.google.com with SMTP id c1so148943pfp.10 for ; Tue, 21 Sep 2021 10:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Ae9N/Ehz4QT7RYpuRU7NvHlnRTxJlESW1W2mEkgbGg=; b=HrvX5kJsYIGMeH1I8RYGxMJhicwcuUre4dw9dg6igYoVAmg6K1EoDXTgulLdsuXLeJ nAWr6aIisvMRpWLJ3ghG3DBxxAmjp3+QTY1SO71lUssLGq584vH692MKKqraRtupGEth FmxA46xlXtQFlLKUqMRKeHkU3UBTLQpKA0UE6bYfiNuog5i/tRJX8v4KYgYX5hTWR0Xu 9Jt46dW2hWOJCDQwks2Hnnq5U8H5sK2HxOyG0cx5UkY6/UKzvb/xOiYWwsnA2S3tsmWs qgxxfOv/sM/3cJLf5zmPYw/C1MWMuYUsNZU/jBtilqnQK8QK6udBCRihU/Zq/vTdXdhe MKxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Ae9N/Ehz4QT7RYpuRU7NvHlnRTxJlESW1W2mEkgbGg=; b=n/LUq7YMyhrPyfaK92ikXJudnVBB4NiLohes06HCJB2fg4L9k+FjkhKFW4VZhRZe/y fV/vL0Pw383XugeEzpSwBXC13q/VhkLaIAvLMFGLyXnfEZlLUQ15akOn8zSj0sFnyZnj vZJteSWyn7zP+CAEnWEwwigyNMc0DR8ndhY4eh8vfYvOAoRRHGyV356GiEpRHFW/YaEp URKJfoEW9aukoDp3bx6by99QIlX60i02ma2g9oQVfsmAUaFb4I82a4Y/O91zeBDXCWEI JR+ihDShVQ3uZjTFFbefRPhgBXOZmd6yhoq/Q0o5x4sWneL0m8q6U4dAdQtHmeH1PFyo AVpw== X-Gm-Message-State: AOAM533Qa4MoIzlp4mZnTlnAuM6uelWyD0Pfl0XzhTeDNj1eqI9aCb3I 0gRNzTORxGBZh7JWI+5xEfguLpSCpcOpZ7/Z X-Google-Smtp-Source: ABdhPJy0/of+yIpHQw/cdmicN4OamsCuh7bjNoQmSndJdYXLU3WcsYAZoIFesoRcGIJoix6tsbWOTA== X-Received: by 2002:a63:774e:: with SMTP id s75mr15830187pgc.73.1632246023625; Tue, 21 Sep 2021 10:40:23 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.167]) by smtp.googlemail.com with ESMTPSA id k190sm19800772pgc.11.2021.09.21.10.40.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 10:40:23 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Sep 2021 23:09:55 +0530 Message-Id: <20210921173955.20408-3-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210921173955.20408-1-vedantparanjape160201@gmail.com> References: <20210921173955.20408-1-vedantparanjape160201@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 3/3] test: gstreamer: Simplify elements' ownerships X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicolas Dufresne , Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In gstreamer, when elements are created, usually a floating [1] reference is returned which simply means, there is no ownership transfer (yet). Once can simply check for NULL and return through an error path, without bothering to clean up. Hence, g_autoptr is not much of help here. If the NULL checks have been passed successfully, elements are ready to use. However, we must claim ownership/reference it before using them via g_object_ref_sink(). This patch build upon this principle and removes the g_autoptr from gstreamer test base class (gstreamer_test.cpp) whereever necessary to tide up the code. [1] https://gstreamer.freedesktop.org/documentation/additional/design/MT-refcounting.html?gi-language=c#refcounting1 Signed-off-by: Vedant Paranjape Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne Reviewed-by: Paul Elder --- test/gstreamer/gstreamer_test.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp index 4171250584e6..227a5c37fbe1 100644 --- a/test/gstreamer/gstreamer_test.cpp +++ b/test/gstreamer/gstreamer_test.cpp @@ -78,18 +78,17 @@ GstreamerTest::~GstreamerTest() int GstreamerTest::createPipeline() { - g_autoptr(GstElement) libcameraSrc = gst_element_factory_make("libcamerasrc", "libcamera"); + libcameraSrc_ = gst_element_factory_make("libcamerasrc", "libcamera"); pipeline_ = gst_pipeline_new("test-pipeline"); - g_object_ref_sink(libcameraSrc); - if (!libcameraSrc || !pipeline_) { + if (!libcameraSrc_ || !pipeline_) { g_printerr("Unable to create create pipeline %p.%p\n", - libcameraSrc, pipeline_); + libcameraSrc_, pipeline_); return TestFail; } - libcameraSrc_ = reinterpret_cast(g_steal_pointer(&libcameraSrc)); + g_object_ref_sink(libcameraSrc_); return TestPass; }