From ec3c68c0f52c2ea03c07372e979c3832987fbc23 Mon Sep 17 00:00:00 2001 From: Eric Sesterhenn Date: Thu, 5 Nov 2009 10:06:50 +0100 Subject: Fix fd leak in libcanberra hi, while playing around with cppcheck, the tool noticed that there is a file descriptor leak: [libcanberra-0.22/src/gstreamer.c:285]: (error) Resource leak: fd Attached patch fixes the leak in two places. Regards, Eric --- src/gstreamer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gstreamer.c b/src/gstreamer.c index 5ff835c..f797984 100644 --- a/src/gstreamer.c +++ b/src/gstreamer.c @@ -277,12 +277,15 @@ static int ca_gst_sound_file_open(ca_sound_file **_f, const char *fn) { if ((fd = open(fn, O_RDONLY)) == -1) return errno == ENOENT ? CA_ERROR_NOTFOUND : CA_ERROR_SYSTEM; - if (!(f = ca_new0(ca_sound_file, 1))) + if (!(f = ca_new0(ca_sound_file, 1))) { + close(fd); return CA_ERROR_OOM; + } if (!(f->fdsrc = gst_element_factory_make("fdsrc", NULL))) { + close(fd); ca_free(f); - return CA_ERROR_OOM; + return CA_ERROR_OOM; } g_object_set(GST_OBJECT(f->fdsrc), "fd", fd, NULL); -- cgit