gbm/dri: fix memory leaks in error path
authorEric Engestrom <eric.engestrom@imgtec.com>
Fri, 27 Jan 2017 17:29:05 +0000 (17:29 +0000)
committerEmil Velikov <emil.l.velikov@gmail.com>
Fri, 27 Jan 2017 17:56:58 +0000 (17:56 +0000)
Signed-off-by: Eric Engestrom <eric.engestrom@imgtec.com>
[Emil Velikov: make sure it builds]
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
src/gbm/backends/dri/gbm_dri.c

index 45cb42a8625f31325191b69f0a25efdeaaeaf52d..ac7ede87b6429da959e4e5671541a6d2fdc26e16 100644 (file)
@@ -695,6 +695,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
          gbm_format = GBM_FORMAT_YUYV;
          break;
       default:
+         dri->image->destroyImage(image);
          return NULL;
       }
       break;
@@ -715,6 +716,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
       gbm_format = gbm_dri_to_gbm_format(dri_format);
       if (gbm_format == 0) {
          errno = EINVAL;
+         dri->image->destroyImage(image);
          return NULL;
       }
       break;
@@ -759,8 +761,10 @@ gbm_dri_bo_import(struct gbm_device *gbm,
 
 
    bo = calloc(1, sizeof *bo);
-   if (bo == NULL)
+   if (bo == NULL) {
+      dri->image->destroyImage(image);
       return NULL;
+   }
 
    bo->image = image;
 
@@ -771,6 +775,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
    if (dri->image->base.version >= 2 &&
        !dri->image->validateUsage(bo->image, dri_use)) {
       errno = EINVAL;
+      dri->image->destroyImage(bo->image);
       free(bo);
       return NULL;
    }