summaryrefslogtreecommitdiffstats
path: root/libmpdemux/tvi_v4l.c
diff options
context:
space:
mode:
authorpl <pl@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-12-19 12:54:06 +0000
committerpl <pl@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-12-19 12:54:06 +0000
commitd8925752b84cfa3570a9d1ef45d490b2d0f0ee0b (patch)
tree82814e3b845dbe5d5774c7e1780984c26362a9a7 /libmpdemux/tvi_v4l.c
parent35c39674d7a68bdeb5eb3f4f7dd175649b4c8f15 (diff)
downloadmpv-d8925752b84cfa3570a9d1ef45d490b2d0f0ee0b.tar.bz2
mpv-d8925752b84cfa3570a9d1ef45d490b2d0f0ee0b.tar.xz
checkings for malloc results (potential memleaks)
btw: C functions in .h files is dirty :) git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3612 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux/tvi_v4l.c')
-rw-r--r--libmpdemux/tvi_v4l.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/libmpdemux/tvi_v4l.c b/libmpdemux/tvi_v4l.c
index 1547ff5e00..5454f120c0 100644
--- a/libmpdemux/tvi_v4l.c
+++ b/libmpdemux/tvi_v4l.c
@@ -227,14 +227,14 @@ tvi_handle_t *tvi_init_v4l(char *device)
/* 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 @@ static int init(priv_t *priv, tvi_param_t *params)
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 @@ static int init(priv_t *priv, tvi_param_t *params)
/* 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);