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

A incorrect free in ddsi_init #1832

Closed
CenTr1X opened this issue Sep 19, 2023 · 2 comments
Closed

A incorrect free in ddsi_init #1832

CenTr1X opened this issue Sep 19, 2023 · 2 comments

Comments

@CenTr1X
Copy link
Contributor

CenTr1X commented Sep 19, 2023

char * procname = ddsrt_getprocessname();
char namebuf[256];
if (procname) {
ddsi_xqos_add_property_if_unset(&gv->default_local_xqos_pp, true, DDS_BUILTIN_TOPIC_PARTICIPANT_PROPERTY_PROCESS_NAME, procname);
ddsrt_free(procname);
}

Here, Cyclone DDS use ddsrt_getprocessname() to get the process name and then free it. But if using freertos + lwip (other architectures may have the same problem), ddsrt_getprocessname() will return the address of pxTCB->pcTaskName, which is managed by freertos and should not be free. In my project, this will lead to a heap management problem.

@eboasson
Copy link
Contributor

eboasson commented Oct 11, 2023

It looks like both Windows and Unix need to dynamically allocate this in some circumstances, so in the interest of keeping the interface of ddsrt_getprocessname straightforward, it should also be allocated dynamically in FreeRTOS.

I suppose that means:

return pcTaskGetName(xTaskGetCurrentTaskHandle());

should read:

  return ddsrt_strdup(pcTaskGetName(xTaskGetCurrentTaskHandle()));

instead (which also requires a #include "dds/ddsrt/string.h").

Checking it is difficult for me. Would you be able to verify that this is the correct fix?

If it works, you're more than welcome to do a PR with the fix, the only obstacle would be that you need to sign the Eclipse Contributor Agreement. That saves me from having to go through the steps (and might reduce the round-trip time a bit) 🙂

@CenTr1X
Copy link
Contributor Author

CenTr1X commented Oct 24, 2023

Thank you for your help! I have applied your solution to my program, and now it works well. And I opened a PR with your fix at #1862 . So I think this issue can be closed.

@CenTr1X CenTr1X closed this as completed Oct 24, 2023
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