diff --git a/src/direct/direct-export-buf.c b/src/direct/direct-export-buf.c index 3db44ac..86203d6 100644 --- a/src/direct/direct-export-buf.c +++ b/src/direct/direct-export-buf.c @@ -172,10 +172,11 @@ static BackingImage *direct_allocateBackingImage(NVDriver *drv, NVSurface *surfa goto import_fail; } - close(memFd); close(memFd2); - memFd = -1; memFd2 = -1; + // memFd file descriptor is closed by CUDA after importing + memFd = -1; + //now map the arrays for (uint32_t i = 0; i < fmtInfo->numPlanes; i++) { @@ -216,15 +217,18 @@ static BackingImage *direct_allocateBackingImage(NVDriver *drv, NVSurface *surfa bail: destroyBackingImage(drv, backingImage); + //another 'free' might occur on this pointer. + //hence, set it to NULL to ensure no operation is performed if this really happens. + backingImage = NULL; import_fail: - if (memFd != 0) { + if (memFd >= 0) { close(memFd); } - if (memFd != 0) { - close(memFd); + if (memFd2 >= 0) { + close(memFd2); } - if (drmFd != 0) { + if (drmFd >= 0) { close(drmFd); } free(backingImage); diff --git a/src/list.c b/src/list.c index 0acac4a..a82e125 100644 --- a/src/list.c +++ b/src/list.c @@ -21,11 +21,7 @@ static void ensure_capacity(Array *arr, uint32_t new_capacity) { } } - if (arr->buf == NULL) { - arr->buf = malloc(arr->capacity * sizeof(void*)); - } else { - arr->buf = realloc(arr->buf, arr->capacity * sizeof(void*)); - } + arr->buf = realloc(arr->buf, arr->capacity * sizeof(void*)); //clear the new part of the array memset(&arr->buf[old_capacity], 0, (arr->capacity - old_capacity) * sizeof(void*)); diff --git a/src/vabackend.c b/src/vabackend.c index 03efbc7..5353d75 100644 --- a/src/vabackend.c +++ b/src/vabackend.c @@ -308,9 +308,7 @@ static void deleteObject(NVDriver *drv, VAGenericID id) { ARRAY_FOR_EACH(Object, o, &drv->objects) if (o->id == id) { remove_element_at(&drv->objects, o_idx); - if (o->obj != NULL) { - free(o->obj); - } + free(o->obj); free(o); //we've found the object, no need to continue break; @@ -2114,6 +2112,8 @@ static VAStatus nvTerminate( VADriverContextP ctx ) CHECK_CUDA_RESULT_RETURN(cu->cuCtxDestroy(drv->cudaContext), VA_STATUS_ERROR_OPERATION_FAILED); drv->cudaContext = NULL; + free(drv); + return VA_STATUS_SUCCESS; }