Skip to content

Commit

Permalink
Merge pull request #303 from akorb/master
Browse files Browse the repository at this point in the history
Fix memory issues
  • Loading branch information
elFarto authored Sep 9, 2024
2 parents 54442d8 + e79eb5b commit 720750a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/direct/direct-export-buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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*));
Expand Down
6 changes: 3 additions & 3 deletions src/vabackend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 720750a

Please sign in to comment.