wcap: Prevent fd leak in wcap_decoder_create() fail path

Signed-off-by: Sergi Granell <xerpi.g.12@gmail.com>
Reviewed-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
Sergi Granell 2017-03-29 22:41:02 +02:00 committed by Quentin Glidic
parent fec723ef56
commit 597dde5cf6
No known key found for this signature in database
GPG Key ID: AC203F96E2C34BB7
1 changed files with 2 additions and 0 deletions

View File

@ -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;
}