-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix memory leaks #24923
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 leaks #24923
Conversation
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
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.
Pull request overview
This pull request fixes memory leaks across various components of radare2 by adding missing free() calls, improving error handling paths, and adding null pointer checks.
Key Changes:
- Added memory cleanup in error paths where allocated structures were not being freed before returning
- Added null pointer validation checks using
R_RETURN_IF_FAILandR_RETURN_VAL_IF_FAILmacros in utility functions - Fixed variable initialization and realloc failure handling to prevent leaks
Reviewed changes
Copilot reviewed 19 out of 25 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| shlr/winkd/winkd.c | Added free(mod) in error paths when length is zero or allocation fails for module listing |
| shlr/java/class.c | Added r_bin_java_fmtype_free(method) when attribute parsing fails |
| libr/util/str.c | Added free(str) before returning NULL on realloc failure |
| libr/util/print.c | Added null pointer checks for RPrint parameter in multiple functions |
| libr/util/charset.c | Added free(res) when buffer length check fails |
| libr/util/asn1.c | Added missing free(object) and r_asn1_free(a) in error paths |
| libr/socket/socket_http_server.c | Added free(hr) after closing HTTP request resources |
| libr/main/radare2.c | Added missing free(bindir) and free(mandir) in cleanup code |
| libr/io/io_cache.c | Added null check for incoming_ci->tree_itv and _io_cache_item_free(_ci) calls on realloc failures |
| libr/flag/flag.c | Added free(itemname) before returning on invalid flag name |
| libr/debug/p/native/linux/linux_debug.c | Added r_debug_pid_free(pid_info) when pid_info is not added to list |
| libr/core/vslides.c | Set o = NULL after freeing to prevent double-free, reordered free operations |
| libr/core/cmd.c | Added free(host) and free(k) in error paths |
| libr/bin/p/bin_dyldcache.c | Added free(deps) when image reading fails |
| libr/bin/mangling/objc.c | Removed redundant conditional checks and added free(name) before reassignment |
| libr/bin/mangling/cxx/cp-demangle.c | Cached template check result in variable to avoid redundant evaluations |
| libr/bin/format/objc/mach0_classes.c | Removed null checks for R_NEW0 allocations (potential issue), added field cleanup in error paths |
| libr/bin/format/mach0/mach0.c | Fixed bug where wrong variable was used for symbol name, added free(symbol.name) |
| libr/bin/format/elf/elf.c | Added free(isym) when import limit is reached |
| libr/asm/parse.c | Added free(opstr) before returning result |
| libr/arch/p/x86_nz/pseudo.c | Fixed variable declaration scope for hcmd, added free(buf) in early return |
| libr/arch/p/cosmac/pseudo.c | Added free(buf) before returning in conditional branch |
| libr/arch/p/arm/armass64.c | Fixed variable name from token to t, added free(t) in multiple error paths |
| libr/anal/sign.c | Added memset initialization for combined_mask when a->bytes->mask is NULL |
| libr/anal/dwarf_process.c | Added cleanup of visited set, free(name) before reassignment, conditional free for result->name, and initialized cas struct |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Description