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

Possibility of memory leaks with asynchronous exceptions #27

Open
arybczak opened this issue Dec 28, 2014 · 5 comments
Open

Possibility of memory leaks with asynchronous exceptions #27

arybczak opened this issue Dec 28, 2014 · 5 comments

Comments

@arybczak
Copy link

Any code that follows the pattern "allocate bare resource using a function imported from C, then create a foreign pointer that manages the resource" needs to mask asynchronous exceptions, since if exception arrives between allocation and wrapping, memory leaks. This is particularly dangerous in connectdb, since such code may eventually run out of reachable database connections, completely blocking the access to the database.

@lpsmith
Copy link
Owner

lpsmith commented Dec 28, 2014

You are correct, and this issue is one that I am well aware of. I just haven't gotten around to reviewing and improving the library... and there's a lot to review.

I'm not quite sure what you mean by "reachable database connections", and blocking access to the database however. Unless you mean leaking an open database connection, and eventually running into the backend's configured connection limit.

@arybczak
Copy link
Author

Unless you mean leaking an open database connection, and eventually running into the backend's configured connection limit.

Yes, that's exactly it.

@lpsmith
Copy link
Owner

lpsmith commented Dec 28, 2014

Ok, well I pushed a fix for #26, how much do you want to fix before I release to hackage?

I would be willing to review and fix the connection functions myself. I don't really want to go through the rest of the library at the moment... I'll probably get around to it someday, but honestly it's not a personal priority at the moment.

@arybczak
Copy link
Author

It looks like securing PGconn, PGresult and PGcancel is easily doable by masking connectdb, connectStart, resultFromConn and getCancel functions, so if you could do that it would be great. I see there are some functions using malloc/free directly that are more subtle to localize and fix. I might actually look at them later myself and secure them appropriately, but it's not critical as I don't use them at the moment.

Btw, thanks for the very fast response!

lpsmith added a commit that referenced this issue Jan 21, 2015
Improves,  but does not close,  issue #27
@lpsmith lpsmith closed this as completed Jul 16, 2015
@lpsmith
Copy link
Owner

lpsmith commented Aug 26, 2016

Err, I don't recall closing this issue, I don't understand why I would have. :-/

@lpsmith lpsmith reopened this Aug 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants