[PATCH weston] wcap: Prevent fd leak in wcap_decoder_create() fail path

Sergi Granell xerpi.g.12 at gmail.com
Wed Mar 29 20:41:02 UTC 2017


Signed-off-by: Sergi Granell <xerpi.g.12 at gmail.com>
---
 wcap/wcap-decode.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/wcap/wcap-decode.c b/wcap/wcap-decode.c
index e3b8985f..7e8c8477 100644
--- a/wcap/wcap-decode.c
+++ b/wcap/wcap-decode.c
@@ -131,6 +131,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;
 	}
@@ -146,6 +147,7 @@ wcap_decoder_create(const char *filename)
 	frame_size = header->width * header->height * 4;
 	decoder->frame = malloc(frame_size);
 	if (decoder->frame == NULL) {
+		close(decoder->fd);
 		free(decoder);
 		return NULL;
 	}
-- 
2.12.2



More information about the wayland-devel mailing list