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 memleak when writer is closed prior to closing containers #303

Merged
merged 1 commit into from
Jul 14, 2022

Conversation

nirosys
Copy link
Contributor

@nirosys nirosys commented Jul 9, 2022

Issue #, if available: None

Description of changes:
ION_WRITER's _pending_temp_entity_pool is moved over to _temp_entity_pool while transitioning from the symtab intercept state, when depth is zero.

If the writer was closed prior to that transition, the data pointed to by _pending_temp_entity_pool would be leaked. This PR adds a function to free the data, and checks during _ion_writer_free to ensure the pending temp entity pool is freed if needed, similar to how the temp entity pool is freed.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The writer's _pending_temp_entity_pool is moved over to
_temp_entity_pool while transitioning from the symtab
intercept state, when depth is zero.

Prior to this commit if the writer was closed prior to that
transition, the data pointed to by _pending_temp_entity_pool
would be leaked. This commit adds checking during
_ion_writer_free to ensure the pending temp entity pool is
freed if needed, similar to how the temp entity pool is freed.
@nirosys nirosys marked this pull request as ready for review July 11, 2022 18:53
writer->_pending_temp_entity_pool = NULL;
}

RETURN(__location_name__, __line__, __count__++, err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an intentional choice not to use iRETURN?

Should this just be a void function since it looks like it can't return anything but IERR_OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea that was intentional. Since the fail label that iRETURN defines isn't used, using it over RETURN only adds to the warnings generated at build.

It could definitely be a void function. I maintained the signature that the other free functions had for writer members, but all of them could be converted to void since all 3 only return IERR_OK.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. So maybe we need a separate (and larger) task to get rid of unnecessary iRETURN usages, if we want to reduce warnings. Approving this PR.

@nirosys nirosys merged commit 20b0c8d into amazon-ion:master Jul 14, 2022
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