fix resource/memory leaks
diff --git a/src/lib/u/iniparser.c b/src/lib/u/iniparser.c
index 37638fe..75150c2 100644
--- a/src/lib/u/iniparser.c
+++ b/src/lib/u/iniparser.c
@@ -227,6 +227,10 @@
}
if ((d == NULL) || (d->val == NULL) || (d->key == NULL) || (d->hash == NULL)) {
fprintf(stderr, "dictionary_new: memory allocation failure\n");
+ free(d->val);
+ free(d->key);
+ free(d->hash);
+ free(d);
d = NULL;
}
return d;
@@ -909,8 +913,10 @@
* Initialize a new dictionary entry
*/
d = dictionary_new(0);
- if (d == NULL)
+ if (d == NULL) {
+ fclose(ini);
return d;
+ }
lineno = 0 ;
while (fgets(lin, ASCIILINESZ, ini)!=NULL) {
lineno++ ;
@@ -922,6 +928,8 @@
/* Valid section name */
strcpy(sec, strlwc(sec));
if (iniparser_add_entry(d, sec, NULL, NULL) != 0) {
+ dictionary_del(d);
+ fclose(ini);
return NULL;
}
} else if (sscanf (where, "%[^=] = \"%[^\"]\"", key, val) == 2
@@ -938,6 +946,8 @@
strcpy(val, strcrop(val));
}
if (iniparser_add_entry(d, sec, key, val) != 0) {
+ dictionary_del(d);
+ fclose(ini);
return NULL;
}
}
diff --git a/src/lib/u/uri.c b/src/lib/u/uri.c
index 25ddb9c..be5fe47 100644
--- a/src/lib/u/uri.c
+++ b/src/lib/u/uri.c
@@ -267,6 +267,7 @@
err:
u_free(q);
u_free(key);
+ hash_free(h);
return NULL;
}
diff --git a/src/lib/wsman-curl-client-transport.c b/src/lib/wsman-curl-client-transport.c
index 5de6d87..2c2f98c 100644
--- a/src/lib/wsman-curl-client-transport.c
+++ b/src/lib/wsman-curl-client-transport.c
@@ -435,6 +435,7 @@
char *_user = NULL, *_pass = NULL;
u_buf_t *response = NULL;
//char *soapaction;
+ char *tmp_str = NULL;
if (!cl->initialized && wsmc_transport_init(cl, NULL)) {
cl->last_error = WS_LASTERR_FAILED_INIT;
@@ -471,7 +472,8 @@
char content_type[64];
snprintf(content_type, 64, "Content-Type: application/soap+xml;charset=%s", cl->content_encoding);
headers = curl_slist_append(headers, content_type);
- usag = malloc(12 + strlen(wsman_transport_get_agent(cl)) + 1);
+ tmp_str = wsman_transport_get_agent(cl);
+ usag = malloc(12 + strlen(tmp_str) + 1);
if (usag == NULL) {
r = CURLE_OUT_OF_MEMORY;
cl->fault_string = u_strdup("Could not malloc memory");
@@ -479,7 +481,8 @@
goto DONE;
}
- sprintf(usag, "User-Agent: %s", wsman_transport_get_agent(cl));
+ sprintf(usag, "User-Agent: %s", tmp_str);
+ free(tmp_str);
headers = curl_slist_append(headers, usag);
#if 0
diff --git a/src/lib/wsman-faults.c b/src/lib/wsman-faults.c
index 6ee1684..c980083 100644
--- a/src/lib/wsman-faults.c
+++ b/src/lib/wsman-faults.c
@@ -635,10 +635,12 @@
/* some default values */
status->fault_detail_code = 0;
status->fault_msg = NULL;
+ free(subcode_value_msg);
return;
}
}
}
+ free(subcode_value_msg);
return;
}
diff --git a/src/lib/wsman-plugins.c b/src/lib/wsman-plugins.c
index 2b9dcd8..798ae46 100644
--- a/src/lib/wsman-plugins.c
+++ b/src/lib/wsman-plugins.c
@@ -216,7 +216,7 @@
} else {
error("Out of memory scanning for plugins.");
}
- if (plugin_path)
+ if (plugin_path)
u_free (plugin_path);
if (retv != 0 && (NULL != plugin))
plugin_free(plugin);
diff --git a/src/lib/wsman-server-api.c b/src/lib/wsman-server-api.c
index 8edfddc..b2cb69d 100644
--- a/src/lib/wsman-server-api.c
+++ b/src/lib/wsman-server-api.c
@@ -120,6 +120,8 @@
soap = ws_context_get_runtime(cntx);
if (listener)
soap->listener = (WsManListenerH *)listener;
+ } else {
+ u_free(listener);
}
//debug_add_handler (debug_message_handler, DEBUG_LEVEL_ALWAYS, NULL);
return (ServerConfig *)soap;
diff --git a/src/lib/wsman-subscription-repository.c b/src/lib/wsman-subscription-repository.c
index d61e395..35016c2 100644
--- a/src/lib/wsman-subscription-repository.c
+++ b/src/lib/wsman-subscription-repository.c
@@ -199,6 +199,8 @@
node = lnode_create(entry);
list_append(subscription_list, node);
debug("subscription file found: %s", namelist[n]->d_name );
+ } else {
+ u_free(buf);
}
u_free(namelist[n]);
}