@@ -1278,6 +1278,8 @@ drm_intel_fake_emit_reloc(drm_intel_bo *bo, uint32_t offset,
if (bo_fake->relocs == NULL) {
bo_fake->relocs =
malloc(sizeof(struct fake_buffer_reloc) * MAX_RELOCS);
+ if (!bo_fake->relocs)
+ return -ENOMEM;
}
r = &bo_fake->relocs[bo_fake->nr_relocs++];
@@ -1597,6 +1599,8 @@ drm_intel_bufmgr_fake_init(int fd, unsigned long low_offset,
drm_intel_bufmgr_fake *bufmgr_fake;
bufmgr_fake = calloc(1, sizeof(*bufmgr_fake));
+ if (!bufmgr_fake)
+ return NULL;
if (pthread_mutex_init(&bufmgr_fake->lock, NULL) != 0) {
free(bufmgr_fake);
@@ -2081,6 +2081,9 @@ aub_write_bo_data(drm_intel_bo *bo, uint32_t offset, uint32_t size)
unsigned int i;
data = malloc(bo->size);
+ if (!data)
+ return;
+
drm_intel_bo_get_subdata(bo, offset, size, data);
/* Easy mode: write out bo with no relocations */
@@ -3914,6 +3914,8 @@ drm_intel_decode(struct drm_intel_decode *ctx)
* checking in statically sized packets.
*/
temp = malloc(size + 4096);
+ if (!temp)
+ return;
memcpy(temp, ctx->base_data, size);
memset((char *)temp + size, 0xd0, 4096);
ctx->data = temp;
This patch adds check for various malloc/calloc function if they were able to allocate memory as requested or not. Return appropriate error if the allocation fails. v2: Rebased to the latest. Signed-off-by: Praveen Paneri <praveen.paneri@intel.com> --- intel/intel_bufmgr_fake.c | 4 ++++ intel/intel_bufmgr_gem.c | 3 +++ intel/intel_decode.c | 2 ++ 3 files changed, 9 insertions(+)