[pulseaudio-discuss] [PATCH] xen:Resource leak in local function alloc_gref() - alloc_fd and dev_fd

Manish Sogi manish.sogi at samsung.com
Wed Jul 1 21:24:19 PDT 2015


The file descriptors need to be close in failure cases otherwise resource
leak is there.

Buglink: https://bugs.freedesktop.org/show_bug.cgi?id=91174#c0

Signed-off-by: Manish Sogi <manish.sogi at samsung.com>
---
 src/modules/xen/module-xenpv-sink.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/modules/xen/module-xenpv-sink.c b/src/modules/xen/module-xenpv-sink.c
index b87f811..4813f10 100644
--- a/src/modules/xen/module-xenpv-sink.c
+++ b/src/modules/xen/module-xenpv-sink.c
@@ -591,6 +591,7 @@ static int alloc_gref(struct ioctl_gntalloc_alloc_gref *gref_, void **addr) {
     dev_fd = open("/dev/xen/gntdev", O_RDWR);
     if (dev_fd<=0) {
         perror("Could not open /dev/xen/gntdev! Have you loaded the xen_gntdev module?");
+        close(alloc_fd);
         return 1;
     }
 
@@ -602,7 +603,7 @@ static int alloc_gref(struct ioctl_gntalloc_alloc_gref *gref_, void **addr) {
     rv = ioctl(alloc_fd, IOCTL_GNTALLOC_ALLOC_GREF, gref_);
     if (rv) {
         pa_log_debug("Xen audio sink: src-add error: %s (rv=%d)\n", strerror(errno), rv);
-        return rv;
+        goto finish;
     }
 
     /*addr=NULL(default),length, prot,             flags,    fd,         offset*/
@@ -610,7 +611,7 @@ static int alloc_gref(struct ioctl_gntalloc_alloc_gref *gref_, void **addr) {
     if (*addr == MAP_FAILED) {
         *addr = 0;
         pa_log_debug("Xen audio sink: mmap'ing shared page failed\n");
-        return rv;
+        goto finish;
     }
 
     pa_log_debug("Xen audio sink: Got grant #%d. Mapped locally at %Ld=%p\n",
@@ -626,7 +627,7 @@ static int alloc_gref(struct ioctl_gntalloc_alloc_gref *gref_, void **addr) {
        if (rv)
        pa_log_debug("gntalloc unmap notify error: %s (rv=%d)\n", strerror(errno), rv);
        */
-
+finish:
     close(alloc_fd);
     close(dev_fd);
 
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list