Browse Source

rls: Fix memory leak with duplicate entries in lists

- When duplicate detection is requested, free the string and container
- When duplicate detection is not requested, insert the duplicate anyway
Hugh Waite 11 years ago
parent
commit
a0c35bbfa8
2 changed files with 10 additions and 4 deletions
  1. 8 4
      modules/rls/list.h
  2. 2 0
      modules/rls/subscribe.c

+ 8 - 4
modules/rls/list.h

@@ -41,9 +41,11 @@ static inline list_entry_t *list_insert(str *strng, list_entry_t *list, int *dup
 	if (cmp == 0)
 	{
 		if (duplicate != NULL)
+		{
 			*duplicate = 1;
-		pkg_free(p);
-		return list;
+			pkg_free(p);
+			return list;
+		}
 	}
 	if (cmp > 0)
 	{
@@ -59,9 +61,11 @@ static inline list_entry_t *list_insert(str *strng, list_entry_t *list, int *dup
 		if (cmp == 0)
 		{
 			if (duplicate != NULL)
+			{
 				*duplicate = 1;
-			pkg_free(p);
-			return list;
+				pkg_free(p);
+				return list;
+			}
 		}
 
 		p->next = q->next;

+ 2 - 0
modules/rls/subscribe.c

@@ -1037,6 +1037,8 @@ int send_resource_subs(char* uri, void* param)
 		LM_WARN("%.*s has %.*s multiple times in the same resource list\n",
 			s->watcher_uri->len, s->watcher_uri->s,
 			s->pres_uri->len, s->pres_uri->s);
+		pkg_free(tmp_str->s);
+		pkg_free(tmp_str);
 		return 1;
 	}