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

Behavior of microros_allocate(0)? #51

Closed
yushijinhun opened this issue Mar 9, 2022 · 2 comments
Closed

Behavior of microros_allocate(0)? #51

yushijinhun opened this issue Mar 9, 2022 · 2 comments

Comments

@yushijinhun
Copy link
Contributor

I found the behavior of microros_allocate() is inconsistent with RCL's default allocator implementation malloc(). When allocating zero size memory area, microros_allocate() returns NULL while malloc() (on Linux) returns a valid memory address.

I encounter this problem when trying to turn on RCL_COMMAND_LINE_ENABLED. I pass an empty commandline argument into rclc_support_init() (argc = 1, argv = {""}), and then ROS crashes at rcl_init because it tries to allocate 0 byte memory.

The workaround is quite simple: just allocate at least 1 byte in microros_allocate() if requested size is 0. However, in the manual of malloc(), it says:

NULL may also be returned by a successful call to malloc() with a size of zero, or by a successful call to calloc() with nmemb or size equal to zero.

I'm not sure whether it's a micro-ROS's bug or RCL's bug.

@pablogs9
Copy link
Member

pablogs9 commented Mar 9, 2022

I guess that we comply with malloc() functionality. As far as we try to save as much memory as possible in the micro-ROS stack, maybe is better to fix the RCL code to handle the NULL return in the CLI parsing.

@yushijinhun
Copy link
Contributor Author

I think the root of the problem is that RCL misses the terminating null byte when copying strings. I opened ros2/rcl#969 to solve this.

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

No branches or pull requests

2 participants