Package: xawtv
Version: 3.94-1.2
Tags: patch

Hi,

I detected some memory leaks in the v4l plugins when I ran valgrind on
them. Please find attached patch to fix that.

Greetings
-- 
Bjoern Erik Nilsen
diff -urN xawtv-3.94.orig/dist/xawtv-3.94/libng/plugins/drv0-v4l2.c 
xawtv-3.94/dist/xawtv-3.94/libng/plugins/drv0-v4l2.c
--- xawtv-3.94.orig/dist/xawtv-3.94/libng/plugins/drv0-v4l2.c   2003-04-09 
20:15:07.000000000 +0200
+++ xawtv-3.94/dist/xawtv-3.94/libng/plugins/drv0-v4l2.c        2006-06-01 
13:40:59.000000000 +0200
@@ -508,7 +508,21 @@
        fprintf(stderr, "v4l2: close\n");
 
     close(h->fd);
+    
+       if (NULL != h->attr) {
+        int i;
+        for (i = 0; i < h->nattr; ++i) {
+            if (NULL != h->attr[i].choices) {
+                free(h->attr[i].choices);
+                h->attr[i].choices = NULL;
+            }
+        }
+        free(h->attr);
+        h->attr = NULL;
+    }
+
     free(h);
+    h = NULL;
     return 0;
 }
 
diff -urN xawtv-3.94.orig/dist/xawtv-3.94/libng/plugins/drv1-v4l.c 
xawtv-3.94/dist/xawtv-3.94/libng/plugins/drv1-v4l.c
--- xawtv-3.94.orig/dist/xawtv-3.94/libng/plugins/drv1-v4l.c    2003-02-14 
15:14:05.000000000 +0100
+++ xawtv-3.94/dist/xawtv-3.94/libng/plugins/drv1-v4l.c 2006-06-01 
13:43:05.000000000 +0200
@@ -469,7 +469,25 @@
        munmap(h->mmap,h->mbuf.size);
     
     close(h->fd);
+    
+    if (NULL != h->attr) {
+        int i;
+        for (i = 0; i < h->nattr; ++i) {
+            if (NULL != h->attr[i].choices) {
+                free(h->attr[i].choices);
+                h->attr[i].choices = NULL;
+            }
+        }
+        free(h->attr);
+        h->attr = NULL;
+    }
+    
+    if (NULL != h->channels) { free(h->channels); h->channels = NULL; }
+    if (NULL != h->buf_v4l)  { free(h->buf_v4l);  h->buf_v4l  = NULL; }
+    if (NULL != h->buf_me)   { free(h->buf_me);   h->buf_me   = NULL; }
+
     free(h);
+    h = NULL;
     return 0;
 }
 

Reply via email to