Skip to content
Snippets Groups Projects
Commit 6f0907b6 authored by vivek's avatar vivek Committed by Kristian Høgsberg
Browse files

wcap: Check for mmap and malloc return value in wcap decode module


Checking for return value in main.c for wcap_decoder_create function
and mmap, malloc return value in wcap_decoder_create function to avoid
crashes

Signed-off-by: default avatarvivek <vivek.ellur@samsung.com>
parent 47792415
No related branches found
No related tags found
No related merge requests found
......@@ -251,6 +251,10 @@ int main(int argc, char *argv[])
}
decoder = wcap_decoder_create(argv[1]);
if (decoder == NULL) {
fprintf(stderr, "Creating wcap decoder failed\n");
exit(EXIT_FAILURE);
}
if (yuv4mpeg2 && isatty(1)) {
fprintf(stderr, "Not dumping yuv4mpeg2 data to terminal. Pipe output to a file or a process.\n");
......
......@@ -126,6 +126,11 @@ wcap_decoder_create(const char *filename)
decoder->size = buf.st_size;
decoder->map = mmap(NULL, decoder->size,
PROT_READ, MAP_PRIVATE, decoder->fd, 0);
if (decoder->map == MAP_FAILED) {
fprintf(stderr, "mmap failed\n");
free(decoder);
return NULL;
}
header = decoder->map;
decoder->format = header->format;
......@@ -137,6 +142,10 @@ wcap_decoder_create(const char *filename)
frame_size = header->width * header->height * 4;
decoder->frame = malloc(frame_size);
if (decoder->frame == NULL) {
free(decoder);
return NULL;
}
memset(decoder->frame, 0, frame_size);
return decoder;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment