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

Mark freed pointer to NULL in wrapper for u_free() #30

Closed
raveendrapadala opened this issue Apr 23, 2014 · 3 comments
Closed

Mark freed pointer to NULL in wrapper for u_free() #30

raveendrapadala opened this issue Apr 23, 2014 · 3 comments

Comments

@raveendrapadala
Copy link

As u_free is a wrapper function, so i think it would be a good idea to mark the freed pointer to NULL.
The advantages can be:

  1. Dangling pointer usage can be caught, if any existing.
  2. Unexpected behaviour due to double free can be eradicated. -- manual page for free says "if free(ptr) has already been called before, undefined behavior occurs. If ptr is NULL, no operation is performed."

Fix Description:-
File Name: memory.c
Path: src/lib/u/memory.c
Macro: u_free
/** \brief Wrapper for free(3), sanity checks the supplied pointer */

define u_free(ptr) if(ptr){free(ptr);ptr=NULL;}

raveendrapadala added a commit to raveendrapadala/openwsman that referenced this issue Apr 23, 2014
Implemented as discussed at Issue 30. The details can be found at: Openwsman#30
This was referenced Apr 23, 2014
@raveendrapadala
Copy link
Author

Hi Klaus,

Related to the memory leaks.
we prepared report by writing a wrapper for malloc, calloc, realloc and free to check for memory leaks. Generated report is given at the end.

We are analyzing this report. It would be great if you can help us finding the potential memory leaks.
Each entry in report can be read as: "filename:LineNumber@Number of Times "

Executed a WS-Man command that has one instance and nearly 60 properties:

Entries in Generated Report:
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/wsman-server.c:104@2times
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/list.c:233 : @12times
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/hash.c:372 : @1time
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/hash.c:305 : @2TIMES
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/hash.c:302 : @2TIMES
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/hash.c:375 : @1Times
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/memory.c:32 : @16times
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/iniparser.c:226 : @1Times
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/memory.c:20 : @31times
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/list.c:73 : @22times
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/iniparser.c:221 : @1time
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/iniparser.c:224 : @1time
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/iniparser.c:225 : @1time
/home/Raveendra_Reddy/13G_WAVE3/build-yocto-sh4/tmp/work/sh4-poky-linux/openwsman-2.4.10-r4.0/openwsman-2.4.10/src/lib/u/hash.c:817 : @1time

@kkaempf
Copy link
Collaborator

kkaempf commented Nov 12, 2014

src/lib/wsman-server.c:104@2times looks harmless. That's the plugin initialization at startup. Memory should be freed at teardown. But the operating system will also take care of this when the process exits

@kkaempf
Copy link
Collaborator

kkaempf commented Nov 12, 2014

src/lib/u/list.c:233 - uhm, that's the create function and its purpose is to malloc. It's the callers responsibility to free memory.

You might be better off with using valgrind (http://valgrind.org/) which does a full coverage

@kkaempf kkaempf closed this as completed Nov 12, 2014
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