[Mplayer-cvslog] CVS: main/libmpdemux tvi_def.h,1.4,1.5 tvi_v4l.c,1.14,1.15

pl pl at mplayer.dev.hu
Wed Dec 19 13:54:09 CET 2001


Update of /cvsroot/mplayer/main/libmpdemux
In directory mplayer:/var/tmp.root/cvs-serv19226

Modified Files:
	tvi_def.h tvi_v4l.c 
Log Message:
checkings for malloc results (potential memleaks)

btw: C functions in .h files is dirty :)


Index: tvi_def.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/tvi_def.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- tvi_def.h	17 Nov 2001 00:23:03 -0000	1.4
+++ tvi_def.h	19 Dec 2001 12:54:06 -0000	1.5
@@ -45,8 +45,9 @@
 
 static void free_handle(tvi_handle_t *h)
 {
-    if (h->priv)
-	free(h->priv);
-    if (h)
+    if (h) {
+	if (h->priv)
+	    free(h->priv);
 	free(h);
+    }
 }

Index: tvi_v4l.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/tvi_v4l.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- tvi_v4l.c	3 Dec 2001 16:38:40 -0000	1.14
+++ tvi_v4l.c	19 Dec 2001 12:54:06 -0000	1.15
@@ -227,14 +227,14 @@
 
     /* set video device name */
     if (!device)
-    {
-	priv->video_device = (char *)malloc(strlen("/dev/video0"));
-	sprintf(priv->video_device, "/dev/video0");
-    }
+	priv->video_device = strdup("/dev/video0");
     else
-    {
-	priv->video_device = (char *)malloc(strlen(device));
-	strcpy(priv->video_device, device);
+	priv->video_device = strdup(device);
+
+    /* allocation failed */
+    if (!priv->video_device) {
+	free_handle(h);
+	return(NULL);
     }
 
     return(h);
@@ -278,6 +278,8 @@
     mp_msg(MSGT_TV, MSGL_INFO, " Inputs: %d\n", priv->capability.channels);
 
     priv->channels = (struct video_channel *)malloc(sizeof(struct video_channel)*priv->capability.channels);
+    if (!priv->channels)
+	goto malloc_failed;
     memset(priv->channels, 0, sizeof(struct video_channel)*priv->capability.channels);
     for (i = 0; i < priv->capability.channels; i++)
     {
@@ -357,10 +359,18 @@
     
     /* video buffers */
     priv->buf = (struct video_mmap *)malloc(priv->nbuf * sizeof(struct video_mmap));
+    if (!priv->buf)
+	goto malloc_failed;
     memset(priv->buf, 0, priv->nbuf * sizeof(struct video_mmap));
     
     return(1);
 
+
+malloc_failed:
+    if (priv->channels)
+	free(priv->channels);
+    if (priv->buf)
+	free(priv->buf);
 err:
     if (priv->fd != -1)
 	close(priv->fd);




More information about the MPlayer-cvslog mailing list