Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory issues #303

Merged
merged 6 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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