[vlc-commits] rtp: use vlc_obj_malloc(), simplify

Rémi Denis-Courmont git at videolan.org
Sun Apr 26 11:06:19 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Apr 26 11:59:24 2020 +0300| [4414e09629f4afb0fdd07c214e7055929af4db97] | committer: Rémi Denis-Courmont

rtp: use vlc_obj_malloc(), simplify

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4414e09629f4afb0fdd07c214e7055929af4db97
---

 modules/access/rtp/rtp.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/modules/access/rtp/rtp.c b/modules/access/rtp/rtp.c
index 264de84415..bd1fcb248a 100644
--- a/modules/access/rtp/rtp.c
+++ b/modules/access/rtp/rtp.c
@@ -155,7 +155,6 @@ static void Close (vlc_object_t *obj)
     if (p_sys->rtcp_fd != -1)
         net_Close (p_sys->rtcp_fd);
     net_Close (p_sys->fd);
-    free (p_sys);
 }
 
 static int OpenSDP(vlc_object_t *obj)
@@ -181,6 +180,10 @@ static int OpenSDP(vlc_object_t *obj)
     if (sdplen < 0)
         return sdplen;
 
+    demux_sys_t *sys = vlc_obj_malloc(obj, sizeof (*sys));
+    if (unlikely(sys == NULL))
+        return VLC_ENOMEM;
+
     struct vlc_sdp *sdp = vlc_sdp_parse((const char *)peek, sdplen);
     if (sdp == NULL) {
         msg_Err(obj, "SDP description parse error");
@@ -280,15 +283,6 @@ static int OpenSDP(vlc_object_t *obj)
 
     vlc_sdp_free(sdp);
 
-    demux_sys_t *sys = malloc(sizeof (*sys));
-    if (sys == NULL)
-    {
-        net_Close(fd);
-        if (rtcp_fd != -1)
-            net_Close(rtcp_fd);
-        return VLC_EGENERIC;
-    }
-
     sys->chained_demux = NULL;
 #ifdef HAVE_SRTP
     sys->srtp = NULL;
@@ -343,6 +337,10 @@ static int OpenURL(vlc_object_t *obj)
     else
         return VLC_EGENERIC;
 
+    demux_sys_t *p_sys = vlc_obj_malloc(obj, sizeof (*p_sys));
+    if (unlikely(p_sys == NULL))
+        return VLC_ENOMEM;
+
     char *tmp = strdup (demux->psz_location);
     if (tmp == NULL)
         return VLC_ENOMEM;
@@ -407,15 +405,6 @@ static int OpenURL(vlc_object_t *obj)
     net_SetCSCov (fd, -1, 12);
 
     /* Initializes demux */
-    demux_sys_t *p_sys = malloc (sizeof (*p_sys));
-    if (p_sys == NULL)
-    {
-        net_Close (fd);
-        if (rtcp_fd != -1)
-            net_Close (rtcp_fd);
-        return VLC_EGENERIC;
-    }
-
     p_sys->chained_demux = NULL;
 #ifdef HAVE_SRTP
     p_sys->srtp         = NULL;



More information about the vlc-commits mailing list