Memory leak in wsman-client.c

View: New views
1 Messages — Rating Filter:   Alert me  

Memory leak in wsman-client.c

by Suresh Sundriyal-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here's another patch to fix a potential memory leak in
src/lib/wsman-client.c.

In the function wsman_make_action, in case of an error condition, we
return a NULL pointer without deallocating the memory for ptr.

The patch refactors the code to avoid this and is a bit more efficient
version of the same code.

--
Regards,
Suresh

Index: src/lib/wsman-client.c
===================================================================
--- src/lib/wsman-client.c (revision 3254)
+++ src/lib/wsman-client.c (working copy)
@@ -85,15 +85,15 @@
 static char*
 wsman_make_action(char *uri, char *op_name)
 {
- size_t len = strlen(uri) + strlen(op_name) + 2;
- char *ptr = (char *) malloc(len);
- if (ptr) {
- if (uri && op_name)
+ if (uri && op_name){
+ size_t len = strlen(uri) + strlen(op_name) + 2;
+ char *ptr = (char *) malloc(len);
+ if(ptr){
  sprintf(ptr, "%s/%s", uri, op_name);
- else
- return NULL;
+ return ptr;
+ }
  }
- return ptr;
+ return NULL;
 }
 
 

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Openwsman-devel mailing list
Openwsman-devel@...
https://lists.sourceforge.net/lists/listinfo/openwsman-devel