After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 787714 - gstomxh265enc:Fix Memory leak in error case
gstomxh265enc:Fix Memory leak in error case
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-omx
1.13.x
Other All
: Normal normal
: 1.13.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2017-09-15 09:15 UTC by Ponnam Srinivas
Modified: 2017-09-22 00:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch file attached (918 bytes, patch)
2017-09-19 04:42 UTC, Ponnam Srinivas
none Details | Review
attached the path (918 bytes, patch)
2017-09-19 11:37 UTC, Ponnam Srinivas
needs-work Details | Review
patch file attached (1.67 KB, patch)
2017-09-20 03:57 UTC, Ponnam Srinivas
none Details | Review
patch file attached (1.68 KB, patch)
2017-09-21 06:18 UTC, Ponnam Srinivas
committed Details | Review

Description Ponnam Srinivas 2017-09-15 09:15:12 UTC
Hi,

 It is observed that there is memory leak in omxmodule.

File Name : omx/gstomxh265enc.c

Function Name : gst_omx_h265_enc_get_caps


In gstomxh265enc.c at gst_omx_h265_enc_get_caps : 450

memory is allocated for caps ,But in case of fail it has not been unref.

code:
caps = gst_caps_new_simple ("video/x-h265",
      "stream-format", G_TYPE_STRING, "byte-stream",
      "alignment", G_TYPE_STRING, "au", NULL);

  GST_OMX_INIT_STRUCT (&param);
  param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index;

  err =
      gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc,
      OMX_IndexParamVideoProfileLevelCurrent, &param);
  if (err != OMX_ErrorNone && err != OMX_ErrorUnsupportedIndex)
    return NULL;



Sol :  gst_caps_unref (caps);

Please provide your feedback.
Comment 1 Sebastian Dröge (slomo) 2017-09-18 10:38:40 UTC
Please attach a patch in "git format-patch" format here. See https://gstreamer.freedesktop.org/documentation/contribute/#how-to-submit-patches
Comment 2 Ponnam Srinivas 2017-09-18 10:41:19 UTC
sure. I am creating the Patch. I will a attach soon
Comment 3 Ponnam Srinivas 2017-09-19 03:47:12 UTC
sorry for delay. definitely will attach the patch today
Comment 4 Ponnam Srinivas 2017-09-19 04:42:56 UTC
Created attachment 360019 [details] [review]
patch file attached
Comment 5 Ponnam Srinivas 2017-09-19 11:37:43 UTC
Created attachment 360039 [details] [review]
attached the path

attached the path. Please review it
Comment 6 Tim-Philipp Müller 2017-09-19 12:36:46 UTC
Comment on attachment 360039 [details] [review]
attached the path

Thanks for the patch!

>--- a/omx/gstomxh265enc.c
>+++ b/omx/gstomxh265enc.c
>@@ -457,8 +457,10 @@ gst_omx_h265_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
>   err =
>       gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc,
>       OMX_IndexParamVideoProfileLevelCurrent, &param);
>-  if (err != OMX_ErrorNone && err != OMX_ErrorUnsupportedIndex)
>-    return NULL;
>+  if (err != OMX_ErrorNone && err != OMX_ErrorUnsupportedIndex) {
>+	gst_caps_unref (caps);
>+	return NULL;
>+    }
> 
>   if (err == OMX_ErrorNone) {
>     switch (param.eProfile) {


I think a nicer fix would be to move the

  caps = gst_caps_new_simple(...)

after the _get_parameter(), i.e. jst before the if (err == OMX_ErrorNone) {...
Comment 7 Ponnam Srinivas 2017-09-20 03:57:09 UTC
Created attachment 360098 [details] [review]
patch file attached

I moved caps as per your suggestion.
patch attached . Please review it
Comment 8 Sebastian Dröge (slomo) 2017-09-20 08:34:36 UTC
Review of attachment 360098 [details] [review]:

::: omx/gstomxh265enc.c
@@ +459,3 @@
+  caps = gst_caps_new_simple ("video/x-h265",
+        "stream-format", G_TYPE_STRING, "byte-stream",
+	      "alignment", G_TYPE_STRING, "au", NULL);

You can move this below the whole switch blocks to the very bottom, then no unreffing is ever needed
Comment 9 Tim-Philipp Müller 2017-09-20 08:53:02 UTC
> You can move this below the whole switch blocks to the very bottom, then no
> unreffing is ever needed

I think in the OMX_ErrorUnsupportedIndex case we just return the caps without profile/level info?
Comment 10 Ponnam Srinivas 2017-09-20 09:07:46 UTC
yes , in the OMX_ErrorUnsupportedIndex case just return the caps 

Please check again .
Comment 11 Sebastian Dröge (slomo) 2017-09-20 14:56:45 UTC
Indeed. Then only the indentation has to be fixed (use gst-indent), and please fix the commit message format:

omxh265enc: Some short explanation
[empty line]
longer explanation
in multiple lines
if necessary
[empty line]
https://bugzilla.gnome.org/show_bug.cgi?id=787714
Comment 12 Ponnam Srinivas 2017-09-21 06:18:26 UTC
Created attachment 360167 [details] [review]
patch file attached

correct the indentation. Please review it .
attach patch file.
Comment 13 Reynaldo H. Verdejo Pinochet 2017-09-21 22:52:58 UTC
Review of attachment 360167 [details] [review]:

You are still missing the bug URL on the commit message. Please add it.

Additionally, A pair of gotos to a single label after "return caps" followed by unref (caps) & return NULL would suffice but if no one else minds, then leave it as it is.
Comment 14 Nicolas Dufresne (ndufresne) 2017-09-22 00:55:53 UTC
Thanks. I fine without goto. For you interest Reynaldo, when you
do "git bz pull ###", the bug link automatically get added.
Comment 15 Nicolas Dufresne (ndufresne) 2017-09-22 00:58:00 UTC
commit 27cd61a21a7f1a9d8a7734a3b302df5d8ef98fd1 (HEAD -> master, origin/master, origin/HEAD)
Author: Ponnam Srinivas <p.srinivas@samsung.com>
Date:   Thu Sep 21 11:36:46 2017 +0530

    omxh265enc: fix caps leak