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 pc_patch_compress leak #112

Closed
wants to merge 4 commits into from

Conversation

achidlow
Copy link
Contributor

This fixes a memory leak in pc_patch_compress. See issue #111.

@achidlow achidlow changed the title Fix patch leak Fix pc_patch_compress leak Jun 21, 2016
@mbredif
Copy link
Contributor

mbredif commented Jun 22, 2016

I came across this issue as well :

They could be made equivalent, saving a upcast-switch-downcast round-trip by putting the stats-freeing code (possibly wrapped in a function such as pc_patch_common_free(PCPATCH*) ) in all the pc_patch_*_free specialized functions.

@achidlow
Copy link
Contributor Author

@mbredif that sounds like a better idea, that would fix any other similar leaks in one go. I'll get on it.

…that from all the different pc_patch_*_free functions.

- Ensure PCPATCH_*->stats is set to a valid value every time one is alloc'd. Vaglrind over unit tests caught a case in pc_patch_dimensional where the PCPATCH_DIMENSIONAL was being memcpy'd and not changing ->stats, resulting in a double-free.
@achidlow
Copy link
Contributor Author

Okay I've made the change @mbredif suggested and made a separate pc_patch_common_free function. This actually revealed an error in pc_patch_dimensional_compress where the stats member was set by memcpy from another PCPATCH_DIMENSIONAL resulting in a double-free. So I went through every case of pcalloc(sizeof(PCPATCH* to make sure the stats member was being set correctly, either to NULL or through pc_stats_clone

@strk
Copy link
Member

strk commented Jan 27, 2017

Is there an existing test in the testsuite that would make the leak evident (and confirm the fix) ?

mbredif added a commit to mbredif/pointcloud that referenced this pull request Feb 2, 2017
@mbredif
Copy link
Contributor

mbredif commented Feb 2, 2017

I have just stumbled yet again on this issue while addressing #135 in mbredif/pointcloud/pointlist_data.

The non-equivalence of pc_patch_*_free(pa) with pc_patch_free((PCPATCH*)pa); is so easy oversee...

I included a quick fix but this PR would be more relevant.

@elemoine
Copy link
Contributor

elemoine commented Feb 2, 2017

The non-equivalence of pc_patch__free(pa) with pc_patch_free((PCPATCH)pa); is so easy oversee...

That's right, but couldn't the rule be "never call pc_patch_[something]_free, and always call pc_patch_free"?

@elemoine
Copy link
Contributor

Replaced by #206.

@elemoine elemoine closed this Apr 30, 2018
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.

None yet

4 participants