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

ensure_pdata: Return unique_ptr so as to not leak resources #269

Merged
merged 2 commits into from Apr 17, 2021

Conversation

detule
Copy link
Collaborator

@detule detule commented Mar 19, 2021

Hi @mloskot @lexicalunit

Fixing here a memory leak I introduced with ensure_pdata in #236

I may be guilty of over-thinking the solution here; any feedback is appreciated. It seemed to me that, given that we are allocating memory in the function, returning a smart rather than raw pointer is preferable. But then, I was struggling with the two code-paths - one where we are just re-casting the pdata_ pointer, and the other where we are returning a pointer to a new allocation. In the former case, where there is another part of the code-base that is responsible for managing that memory allocation, I ended up returning a unique_ptr with a trivial deleter.

Happy to post the valgrind stats, but the leak is pretty obvious.

Depending on the code-path we return either a unique_ptr with a trivial
deleter (bound column: we are just re-casting something stored in pdata_),
or a proper unique_ptr (unbound column: we are allocating memory in this
function and calling SQLGetData).
Copy link
Member

@mloskot mloskot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uses of the deleter needs some comments

nanodbc/nanodbc.cpp Show resolved Hide resolved
Copy link
Member

@mloskot mloskot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/cc @lexicalunit

@mloskot mloskot added this to the 2.14+ milestone Mar 23, 2021
@detule
Copy link
Collaborator Author

detule commented Apr 17, 2021

Hi / ping - let me know if I can do anything else.

Thanks!

@mloskot mloskot merged commit 20ecbf1 into nanodbc:master Apr 17, 2021
@mloskot
Copy link
Member

mloskot commented Apr 17, 2021

Sorry for delay, @detule , it's merged now. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants