Module: kamailio
Branch: master
Commit: b27384a0a7c6567a9ecebab3f987079ad0ff7366
URL:
https://github.com/kamailio/kamailio/commit/b27384a0a7c6567a9ecebab3f987079…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-03-27T11:48:33+02:00
p_usrloc: free allocated items in case of no more memory during domain add
---
Modified: modules/p_usrloc/dlist.c
---
Diff:
https://github.com/kamailio/kamailio/commit/b27384a0a7c6567a9ecebab3f987079…
Patch:
https://github.com/kamailio/kamailio/commit/b27384a0a7c6567a9ecebab3f987079…
---
diff --git a/modules/p_usrloc/dlist.c b/modules/p_usrloc/dlist.c
index 5c16508..75914f5 100644
--- a/modules/p_usrloc/dlist.c
+++ b/modules/p_usrloc/dlist.c
@@ -52,7 +52,7 @@ static inline struct domain_list_item * find_dlist (str *name) {
for (item = domain_list; item != NULL; item = item->next) {
if (item->name.len == name->len
- && memcmp (item->name.s, name->s, name->len) == 0) {
+ && memcmp (item->name.s, name->s, name->len) == 0) {
return item;
}
}
@@ -64,16 +64,17 @@ static inline struct domain_list_item * find_dlist (str *name) {
static inline struct domain_list_item * add_to_dlist (str *name, int type) {
struct domain_list_item *item;
- int i;
+ int i;
item = (struct domain_list_item *)
- pkg_malloc (sizeof (struct domain_list_item));
+ pkg_malloc (sizeof (struct domain_list_item));
if (item == NULL) {
- LM_ERR("Out of shared memory.\n");
+ LM_ERR("Out of pkg memory.\n");
return NULL;
}
item->name.s = (char *) pkg_malloc (name->len + 1);
if (item->name.s == NULL) {
- LM_ERR("Out of shared memory.\n");
+ LM_ERR("Out of pkg memory (1).\n");
+ pkg_free(item);
return NULL;
}
memcpy (item->name.s, name->s, name->len);
@@ -86,7 +87,9 @@ static inline struct domain_list_item * add_to_dlist (str *name, int
type) {
item->domain.table = (hslot_t*)pkg_malloc(sizeof(hslot_t) * ul_hash_size);
if (!item->domain.table) {
- LM_ERR("no memory left 2\n");
+ LM_ERR("Out of pkg memory (2)\n");
+ pkg_free(item->name.s);
+ pkg_free(item);
return NULL;
}