Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

adding decompress to free(state) before return (targeting Lunar)#1313

Merged
dirk-thomas merged 3 commits intolunar-develfrom
pr1293
Jan 29, 2018
Merged

adding decompress to free(state) before return (targeting Lunar)#1313
dirk-thomas merged 3 commits intolunar-develfrom
pr1293

Conversation

@dirk-thomas
Copy link
Copy Markdown
Member

Replaces #1293 targeting the latest development branch.

ret = roslz4_compressStart(&stream, block_size_id);
if (ret != ROSLZ4_OK) { return ret; }
if (ret != ROSLZ4_OK) {
roslz4_compressEnd(&stream);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems kind of weird to call compressEnd when compressStart is the one that is failing. I think it might make more sense to fix roslz4_compressStart so that if the call to streamResizeBuffer fails, it calls streamStateFree and then returns the error. What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looking at the current implementation of these functions the patch looks good to me (compressStart is doing two things which can individually fail). Maybe you can clarify what you think can go wrong with this change?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This change will work fine, but I'm suggesting that the contract with roslz4_compressStart should be that it either succeeds with some memory allocated, or should fail with no visible side-effects. That would mean that if something failed internally, it would clean up after itself and not depend on the caller to cleanup for it. This would also make it easier for any future user of the API to use it, since they wouldn't have to remember to cleanup on failure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will consider to merge the current patch as-is. Please feel free to refactor the current API / implementation in a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, that sounds fine.

ret = roslz4_decompressStart(&stream);
if (ret != ROSLZ4_OK) { return ret; }
if (ret != ROSLZ4_OK) {
roslz4_decompressEnd(&stream);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same idea here, though in this case, I don't think that roslz4_decompressStart can leak memory on an allocation failure, so we might not want to change this at all.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree with you that this shouldn't be necessary since roslz4_decompressStart only allocates when returning OK. So in case of it failing it doesn't need to deallocate anything.

@dirk-thomas dirk-thomas merged commit 3ad74c7 into lunar-devel Jan 29, 2018
@dirk-thomas dirk-thomas deleted the pr1293 branch January 29, 2018 20:27
dirk-thomas added a commit that referenced this pull request Feb 9, 2018
* adding decompress to free(state) before return

* copy paste typo error on roslz4_decompressEnd

* revert unnecessary change
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants