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>
dev
Sergi Granell 8 years ago committed by Quentin Glidic
parent fec723ef56
commit 597dde5cf6
No known key found for this signature in database
GPG Key ID: AC203F96E2C34BB7
  1. 2
      wcap/wcap-decode.c

@ -131,6 +131,7 @@ wcap_decoder_create(const char *filename)
PROT_READ, MAP_PRIVATE, decoder->fd, 0); PROT_READ, MAP_PRIVATE, decoder->fd, 0);
if (decoder->map == MAP_FAILED) { if (decoder->map == MAP_FAILED) {
fprintf(stderr, "mmap failed\n"); fprintf(stderr, "mmap failed\n");
close(decoder->fd);
free(decoder); free(decoder);
return NULL; return NULL;
} }
@ -146,6 +147,7 @@ wcap_decoder_create(const char *filename)
frame_size = header->width * header->height * 4; frame_size = header->width * header->height * 4;
decoder->frame = malloc(frame_size); decoder->frame = malloc(frame_size);
if (decoder->frame == NULL) { if (decoder->frame == NULL) {
close(decoder->fd);
free(decoder); free(decoder);
return NULL; return NULL;
} }

Loading…
Cancel
Save