From 45643adb036c3bb40a7e400203499abb4ad7a3dd Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Tue, 23 Mar 2021 03:07:22 +0100 Subject: [PATCH] win-dshow: Check return values for memory allocation functions Since some of these run inside the virtual cam module, we should be a good guest and not crash the host process if we run out of memory. --- plugins/win-dshow/shared-memory-queue.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/win-dshow/shared-memory-queue.c b/plugins/win-dshow/shared-memory-queue.c index 87b8ffac6..f1cdbf7ae 100644 --- a/plugins/win-dshow/shared-memory-queue.c +++ b/plugins/win-dshow/shared-memory-queue.c @@ -90,6 +90,10 @@ video_queue_t *video_queue_create(uint32_t cx, uint32_t cy, uint64_t interval) vq.header = (struct queue_header *)MapViewOfFile( vq.handle, FILE_MAP_ALL_ACCESS, 0, 0, 0); + if (!vq.header) { + CloseHandle(vq.handle); + return NULL; + } memcpy(vq.header, &header, sizeof(header)); for (size_t i = 0; i < 3; i++) { @@ -98,6 +102,10 @@ video_queue_t *video_queue_create(uint32_t cx, uint32_t cy, uint64_t interval) vq.frame[i] = ((uint8_t *)vq.header) + off + FRAME_HEADER_SIZE; } pvq = malloc(sizeof(vq)); + if (!pvq) { + CloseHandle(vq.handle); + return NULL; + } memcpy(pvq, &vq, sizeof(vq)); return pvq; } @@ -113,8 +121,16 @@ video_queue_t *video_queue_open() vq.header = (struct queue_header *)MapViewOfFile( vq.handle, FILE_MAP_READ, 0, 0, 0); + if (!vq.header) { + CloseHandle(vq.handle); + return NULL; + } struct video_queue *pvq = malloc(sizeof(vq)); + if (!pvq) { + CloseHandle(vq.handle); + return NULL; + } memcpy(pvq, &vq, sizeof(vq)); return pvq; }