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(bindings/C): fix the memory found in valgrind. #2673

Merged
merged 7 commits into from
Jul 20, 2023

Conversation

xyjixyjixyji
Copy link
Contributor

This PR fix the memory leak found in the tests in #2653.

I believe the memory leak is not completely fixed and it could be bettered through more tests on the C binding functionalities.

@xyjixyjixyji
Copy link
Contributor Author

There is still an invalid read problem in the list test.

@xyjixyjixyji
Copy link
Contributor Author

xyjixyjixyji commented Jul 19, 2023

I think that the problem originates from the opendal_list_entry_path()

(*self.inner).path().as_ptr() as *const c_char

The path() returns a &str, which is a reference to the String typed path. And we are taking the pointer of that String directly. I am doing this because I don't want to wrap a opendal_string type, that seems overly verbose...... When I implemented that, I didn't think that was an issue since as long as the user calls opendal_list_entry_path(), the Entry must be alive and the String must be on heap.

I think the problem is that Rust String is not nul-terminated in memory..... Since valgrind reports this, I think we'd better fix this.

Now its fixed.

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@Xuanwo Xuanwo merged commit 442475e into apache:main Jul 20, 2023
@oowl oowl mentioned this pull request Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants