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 memory leak on Windows #22

Merged
merged 3 commits into from
Apr 27, 2016
Merged

Fix memory leak on Windows #22

merged 3 commits into from
Apr 27, 2016

Conversation

codebot
Copy link
Member

@codebot codebot commented Mar 25, 2016

Unfortunately Windows throws a compiler warning when it sees strdup(); it wants to see _strdup() instead.

@tfoote
Copy link

tfoote commented Mar 25, 2016

Might it be better to use malloc and strncpy instead to avoid hidden mallocs: http://stackoverflow.com/a/14021507/604099 It's only one more line of code to explicitly malloc and copy.

@codebot
Copy link
Member Author

codebot commented Mar 25, 2016

I'm not sure what the rest of the Fast-RTPS codebase looks like; I was just trying to get rid of a compiler warning 🐐 how do people normally use TypeSupport::setName() ?

@jacquelinekay
Copy link
Contributor

I haven't mucked around with this part of the codebase very much. @esteve would probably know since he worked a bunch with the TypeSupport to implement C typesupport. (Also, that reminds me--Esteve, you should probably watch the changes we're making to this repo because any changes to files that your pull request moves into a different file will essentially be lost if you don't rebase carefully.)

@codebot
Copy link
Member Author

codebot commented Mar 26, 2016

a ha! great catch Tully. Looks like setName comes from here:

https://github.com/eProsima/Fast-RTPS/blob/master/include/fastrtps/TopicDataType.h

which is looking for a const char * and just passing that to the std::string constructor. So indeed, this would be a memory leak, since setName() isn't taking ownership.

looks to me like we can pass name.c_str() to setName(). Is that how it looks to you as well?

@tfoote
Copy link

tfoote commented Mar 26, 2016

Yeah, it's just turning it back into a string. Passing the .c_str() to it should be adaquate. There are several other instances following that pattern. At least one in parameters and one in QoS.

@codebot codebot force-pushed the patch-2 branch 2 times, most recently from 19bc9ec to 8e501cd Compare April 1, 2016 18:42
pull in upstream changes
@codebot codebot changed the title Use _strdup() instead of strdup() on Windows Fix memory leak on Windows Apr 1, 2016
@codebot
Copy link
Member Author

codebot commented Apr 1, 2016

I think this is looking OK now. CI results:
Linux: linux: http://ci.ros2.org/job/ci_linux/1145/
OSX: http://ci.ros2.org/job/ci_osx/927/
Windows: http://ci.ros2.org/job/ci_windows/1205/

The Linux and OSX results are clean. The Windows one has various test failures because it ran on Windows 10 on windshield. I'll look into figuring out what's going on with windshield, but I don't think any of those failures are new (for windshield). At least there is one less MSVC warning now, which actually led to getting rid of this memory leak 😮

@dirk-thomas
Copy link
Member

@codebot
Copy link
Member Author

codebot commented Apr 1, 2016

@dirk-thomas yeah there are warnings in other files; I was just trying to fix up this file first.

@codebot
Copy link
Member Author

codebot commented Apr 1, 2016

if it's best to couple them together, I can also change ServiceTypeSupport.cpp and squash into this commit. Would that be better?

@dirk-thomas
Copy link
Member

Since ServiceTypeSupport.cpp has the exact same code with the exact same warnings as this MessageTypeSupport.cpp I would say they can be fixed together in this single PR.

@codebot
Copy link
Member Author

codebot commented Apr 1, 2016

OK sounds good, thanks. I'll add those changes to this PR.

codebot added 2 commits April 1, 2016 14:17
Remove fixed guard conditions
Also make explicit static downcast to 32-bit to prevent MSVC compiler warning
@codebot
Copy link
Member Author

codebot commented Apr 1, 2016

OK now we're down to only 5 warnings left on windows HOORAY 😀 I'll go after those in a different PR, since the remaining ones are unrelated to these fixes.

CI looks fine to me; all issues seem unrelated to these changes:
linux: http://ci.ros2.org/job/ci_linux/1147/
osx: http://ci.ros2.org/job/ci_osx/930/
windows: http://ci.ros2.org/job/ci_windows/1209/

@wjwwood
Copy link
Member

wjwwood commented Apr 1, 2016

lgtm

@dirk-thomas
Copy link
Member

Can this be squashed and merged?

@codebot
Copy link
Member Author

codebot commented Apr 27, 2016

i'll squash it right now

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.

5 participants