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

Fix memory leaks and improve error code path #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

charignon
Copy link

Description

This commit refactors the error paths for
method_logreader_each and method_hash_each to use common error
handling logic instead of duplicating code. In these error paths we forgot to call sparkey_logiter_close(&logiter);, leaking memory. This refactoring, makes it easier to
see what is deallocated and fixes the leaks mentioned above.

I added the return Qnil; to both functions to avoid compiler warning on reaching the end of non a void function without a return value.

Test Plan

I compiled the code and ran the unit tests.

@emnl
Copy link
Owner

emnl commented Feb 23, 2017

Nice catch!

Is there anyway of avoiding GOTO while still doing all the fancy refactoring and leak-stopping? GOTO rubs me the wrong way even though this was one of the nicest GOTO I've seen in quite some time.

We forgot to call `sparkey_logiter_close(&logiter);` in four code paths
leaking memory. This commit refactors the error paths for
`method_logreader_each` and `method_hash_each` to use common error
handling logic instead of duplicating code. This also makes it easier to
see what is deallocated and fixes the leaks mentioned above.
@charignon charignon force-pushed the lc/improve_failure_dealloc_and_fix_leak branch from e86dc4a to 3d8967b Compare February 24, 2017 04:17
@charignon
Copy link
Author

I sent a version without GOTO using a function, let me know what you think @emnl.

@charignon
Copy link
Author

Could you please take a look @emnl ?

@charignon
Copy link
Author

@emnl ?

@charignon
Copy link
Author

@jtai

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

Successfully merging this pull request may close these issues.

2 participants