vkr: set a limit on decoder temp pool size

Add VKR_CS_DECODER_TEMP_POOL_MAX_SIZE and set it to 64MiB.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
macos/master
Chia-I Wu 3 years ago
parent 44448cf75c
commit eb98abc86e
  1. 6
      src/vkr_cs.c
  2. 3
      src/vkr_cs.h

@ -219,6 +219,8 @@ vkr_cs_decoder_gc_temp_pool(struct vkr_cs_decoder *dec)
pool->reset_to = pool->buffers[0]; pool->reset_to = pool->buffers[0];
pool->cur = pool->buffers[0]; pool->cur = pool->buffers[0];
pool->total_size = pool->end - pool->cur;
vkr_cs_decoder_sanity_check(dec); vkr_cs_decoder_sanity_check(dec);
} }
@ -332,10 +334,14 @@ vkr_cs_decoder_alloc_temp_internal(struct vkr_cs_decoder *dec, size_t size)
if (!buf_size) if (!buf_size)
return false; return false;
if (buf_size > VKR_CS_DECODER_TEMP_POOL_MAX_SIZE - pool->total_size)
return false;
uint8_t *buf = malloc(buf_size); uint8_t *buf = malloc(buf_size);
if (!buf) if (!buf)
return false; return false;
pool->total_size += buf_size;
pool->buffers[pool->buffer_count++] = buf; pool->buffers[pool->buffer_count++] = buf;
pool->reset_to = buf; pool->reset_to = buf;
pool->cur = buf; pool->cur = buf;

@ -17,6 +17,8 @@
#include "vkr_object.h" #include "vkr_object.h"
#define VKR_CS_DECODER_TEMP_POOL_MAX_SIZE (64u * 1024 * 1024)
struct iovec; struct iovec;
struct vkr_cs_encoder { struct vkr_cs_encoder {
@ -50,6 +52,7 @@ struct vkr_cs_decoder_temp_pool {
uint8_t **buffers; uint8_t **buffers;
uint32_t buffer_count; uint32_t buffer_count;
uint32_t buffer_max; uint32_t buffer_max;
size_t total_size;
uint8_t *reset_to; uint8_t *reset_to;

Loading…
Cancel
Save