Close the decoder->fd resource if mmap fails.  Unmap the
decoder->map and close the decoder->fd if the decoder->frame
memory allocation fails.

Although short-lived in the context of where wcap_decoder_create
is currently used (i.e. in main), not closing the fd before
returning NULL in these cases introduces a resource leak.

Signed-off-by: U. Artie Eoff <ullysses.a.e...@intel.com>
---
 wcap/wcap-decode.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/wcap/wcap-decode.c b/wcap/wcap-decode.c
index 76ecc2f..8909982 100644
--- a/wcap/wcap-decode.c
+++ b/wcap/wcap-decode.c
@@ -128,6 +128,7 @@ wcap_decoder_create(const char *filename)
                            PROT_READ, MAP_PRIVATE, decoder->fd, 0);
        if (decoder->map == MAP_FAILED) {
                fprintf(stderr, "mmap failed\n");
+               close(decoder->fd);
                free(decoder);
                return NULL;
        }
@@ -143,6 +144,8 @@ wcap_decoder_create(const char *filename)
        frame_size = header->width * header->height * 4;
        decoder->frame = malloc(frame_size);
        if (decoder->frame == NULL) {
+               munmap(decoder->map, decoder->size);
+               close(decoder->fd);
                free(decoder);
                return NULL;
        }
-- 
1.8.5.3

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to