-
Notifications
You must be signed in to change notification settings - Fork 135
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
Avoid use-after-free warning #100
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 |
---|---|---|
|
@@ -340,6 +340,7 @@ xrealloc_impl(void *ptr, size_t new_size, const char *file, int line, | |
new_ptr = realloc(ptr, new_size); | ||
if (new_ptr != NULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next, we check if we were successful. As a side note, we could save ourselves a bit of work if we checked not only that |
||
{ | ||
ptr = NULL; | ||
hash_table_del(xmalloc_table, ptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the reallocation was successful, we need to remove the old pointer from the hash table, then add the new one. However, setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the error of my ways :) but does So we reallocated to
Sure, I was trying to build things on alpine:latest; which comes with Here's the compiler warning, which causes trouble when building with
So anyway, while you are right, gcc doesnt' understand/spot the use of the hash-table, which needs to old Anyway, we want to keep Also, after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
hash_table_add(xmalloc_table, new_ptr, (int)new_size, file, line, func); | ||
} | ||
|
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.
Here, we attempt to allocate a new object with the new size. If successful, the old object will be freed.