-
Notifications
You must be signed in to change notification settings - Fork 189
Fix dangling pointer after client.close #527
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 dangling pointer after client.close #527
Conversation
This looks like a reasonable fix to me. Can you also update the changelog file, by adding a bullet point in the "unreleased" section the way it's been done in the past? |
06c5190
to
2b88604
Compare
Great, I've made the changes you requested! Please take a look and let me know if everything looks good to you. If there's anything else you need me to do or if you have any further suggestions, feel free to let me know! 😬 |
@aharpervc I've just solved some merge conflicts. Let me know I you need me to do something else to merge this PR 🙃 |
I'd like to have our CI jobs run for it, but I'm not seeing that integration show up on this PR. I'm guessing that's due to the "Build forked pull requests" setting being turned off at the moment... I'll turn it on and see what happens. |
You might need to push to this branch again, can you try that? For example, you can probably squash this branch down to 1 commit & force push. |
We recently encountered an unexpected Segmentation Fault Error when checking whether a client was dead after closing it. To consider this in the future, I've updated the test cases for the client to include this scenario, so we can catch any issues earlier on.
We recently encountered an unexpected Segmentation Fault Error while checking if a client was dead after closing it. Upon investigation, we discovered that the issue was caused by deallocating all memory used by the client structure without setting the pointer to NULL after closing the client connection through dbclose. This resulted in a dangling pointer, which led to the Segmentation Fault when we tried to check whether the client was dead using TDS dbdead. To prevent this issue from occurring again, I have made the necessary updates to set the client pointer to NULL after every dbclose. This will ensure that we avoid any dangling pointers and keep our code running smoothly.
ac57db1
to
7fe8c8e
Compare
@aharpervc all tests passed! Sorry for the long wait btw, busy month 😅 |
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.
This seems fine to me. I think it's probably best as just 1 commit in the master history, any objections to the "squash & merge" feature?
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.
Given the context of the issue and the PR description, the changes also look good to me.
@matias-martini nicely applied TDD here (first committing a failing test before committing the fix), so merge-commit and rebase would be good. Still, squashing gives the advantage that you find the fix and the test immediately when browsing the Git history at a later point.
@aharpervc @andyundso Totally onboard with 'Squash and merge' for a clearer history! 😄 Thanks again for taking the time to review the changes! |
Context
Hey there!
Firstly, I want to express my appreciation for the hard work and dedication that you have put into maintaining this project. Your efforts have been incredibly valuable to me and many others in the community.
Well, as reported in the issue #519, we ran into an unexpected Segmentation Fault Error while verifying whether a client was dead after closing it. Upon investigation, we discovered (following the leads of @aharpervc ) that the root cause of the issue was that by calling
dbclose
, we were deallocating memory used by the client structure without setting the pointer to NULL after closing the client connection.This led to a dangling pointer, which ultimately resulted in the Segmentation Fault error when we tried to check whether the client was dead using TDS
dbdead
(here).To prevent this issue from happening again, I've made the necessary updates to ensure that the client pointer is set to NULL after every
dbclose
. This fix will help us avoid any dangling pointers and keep our code running smoothly.I also tested this locally both before and after building the gem with the changes and everything is working like a charm now!
I wanted to note that while another solution would have checked whether the client was closed (
cwrap->closed
) before callingdbdead
, I didn't feel comfortable leaving any dangling pointers. 😅Let me know if you have any questions or concerns.
Changelog
client.dead?
after closing the connection in the Client test cases.dbclose
.