[Mesa-stable] [PATCH 07/10] gbm: unify error handling in gbm_dri_bo_import()
Emil Velikov
emil.l.velikov at gmail.com
Mon Oct 16 16:04:09 UTC 2017
From: Emil Velikov <emil.velikov at collabora.com>
Fold the error handling for image creation/duplication in a single
place.
Effectively providing the same errno across the board and plugging a
memory leak in the GBM_BO_IMPORT_WL_BUFFER case.
Cc: mesa-stable at lists.freedesktop.org
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
src/gbm/backends/dri/gbm_dri.c | 35 +++++++++++++----------------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index d7cf01fc6b4..c39ee9c9a53 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -888,9 +888,9 @@ gbm_dri_bo_import(struct gbm_device *gbm,
{
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
- __DRIimage *image;
+ __DRIimage *image = NULL;
unsigned dri_use = 0;
- int gbm_format;
+ int gbm_format = 0;
unsigned query; /* EGLBoolean, but we cannot include the header */
if (dri->image == NULL) {
@@ -935,17 +935,9 @@ gbm_dri_bo_import(struct gbm_device *gbm,
image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
image = dri->image->dupImage(image, NULL);
query = dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
- if (!query) {
- errno = EINVAL;
- dri->image->destroyImage(image);
+ if (!query)
break;
- }
gbm_format = gbm_dri_to_gbm_format(dri_format);
- if (gbm_format == 0) {
- errno = EINVAL;
- dri->image->destroyImage(image);
- return NULL;
- }
break;
}
@@ -973,10 +965,6 @@ gbm_dri_bo_import(struct gbm_device *gbm,
&fd_data->fd, 1,
&stride, &offset,
NULL);
- if (image == NULL) {
- errno = EINVAL;
- return NULL;
- }
gbm_format = fd_data->format;
break;
}
@@ -1008,20 +996,23 @@ gbm_dri_bo_import(struct gbm_device *gbm,
fd_data->offsets,
0, 0, 0, 0,
&error, NULL);
- if (image == NULL) {
- errno = ENOSYS;
- return NULL;
- }
-
gbm_format = fourcc;
break;
}
default:
- errno = ENOSYS;
- return NULL;
+ break;
}
+ if (image == NULL) {
+ errno = EINVAL;
+ return NULL;
+ }
+ if (gbm_format == 0) {
+ errno = EINVAL;
+ dri->image->destroyImage(image);
+ return NULL;
+ }
bo = calloc(1, sizeof *bo);
if (bo == NULL) {
--
2.14.1
More information about the mesa-stable
mailing list