Explorar o código

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.
Richard Stanway %!s(int64=4) %!d(string=hai) anos
pai
achega
45643adb03
Modificáronse 1 ficheiros con 16 adicións e 0 borrados
  1. 16 0
      plugins/win-dshow/shared-memory-queue.c

+ 16 - 0
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;
 }