-
Notifications
You must be signed in to change notification settings - Fork 1
Improve platform code robustness and fix bugs. #61
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -82,6 +82,11 @@ static void ion_alloc(int fd_ion, ion_alloc_info_t* info) { | |||||||||||
| info->fd = ifd.fd; | ||||||||||||
| info->padd = (void*)ipd.phys_addr; | ||||||||||||
| info->vadd = mmap(0, info->size, PROT_READ | PROT_WRITE, MAP_SHARED, info->fd, 0); | ||||||||||||
| if (info->vadd == MAP_FAILED) { | ||||||||||||
| fprintf(stderr, "ION mmap failed\n"); | ||||||||||||
| close(info->fd); | ||||||||||||
| info->vadd = NULL; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| static void ion_free(int fd_ion, ion_alloc_info_t* info) { | ||||||||||||
|
|
@@ -339,12 +344,31 @@ SDL_Surface* PLAT_initVideo(void) { | |||||||||||
| vid.fd_fb = open("/dev/fb0", O_RDWR); | ||||||||||||
| vid.fd_ion = open("/dev/ion", O_RDWR); | ||||||||||||
| vid.fd_mem = open("/dev/mem", O_RDWR); | ||||||||||||
| if (vid.fd_fb < 0 || vid.fd_ion < 0 || vid.fd_mem < 0) { | ||||||||||||
| LOG_error("Failed to open device files (fb=%d ion=%d mem=%d)\n", vid.fd_fb, vid.fd_ion, | ||||||||||||
| vid.fd_mem); | ||||||||||||
|
||||||||||||
| vid.fd_mem); | |
| vid.fd_mem); | |
| if (vid.fd_fb >= 0) close(vid.fd_fb); | |
| if (vid.fd_ion >= 0) close(vid.fd_ion); | |
| if (vid.fd_mem >= 0) close(vid.fd_mem); |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource leak: When mmap fails, the successfully opened file descriptors (vid.fd_fb, vid.fd_ion, vid.fd_mem) should be closed before returning NULL.
Add cleanup:
if (vid.de_mem == MAP_FAILED) {
LOG_error("Failed to mmap display engine\n");
close(vid.fd_mem);
close(vid.fd_ion);
close(vid.fd_fb);
return NULL;
}| LOG_error("Failed to mmap display engine\n"); | |
| LOG_error("Failed to mmap display engine\n"); | |
| close(vid.fd_mem); | |
| close(vid.fd_ion); | |
| close(vid.fd_fb); |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,6 +107,12 @@ void ion_alloc(int ion_fd, ion_alloc_info_t* info) { | |||||||
| info->fd = ifd.fd; | ||||||||
| info->padd = (void*)spd.phys_addr; | ||||||||
| info->vadd = mmap(0, info->size, PROT_READ | PROT_WRITE, MAP_SHARED, info->fd, 0); | ||||||||
| if (info->vadd == MAP_FAILED) { | ||||||||
| fprintf(stderr, "ION mmap failed\n"); | ||||||||
|
||||||||
| fprintf(stderr, "ION mmap failed\n"); | |
| fprintf(stderr, "ION mmap failed\n"); | |
| close(info->fd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource leak: When mmap fails,
info->fd(created by ION_IOC_MAP ioctl at line 78-79) should be closed before returning, as it won't be used.Add cleanup: