[sr-dev] git:master: dialog: break loop when profile entry doesn't exist

Alex Hermann alex at speakup.nl
Mon Nov 3 10:34:03 CET 2014


Module: sip-router
Branch: master
Commit: a65a212c1e7587182f113a94f3d0d8b46c97baa0
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=a65a212c1e7587182f113a94f3d0d8b46c97baa0

Author: Alex Hermann <alex at speakup.nl>
Committer: Alex Hermann <alex at speakup.nl>
Date:   Thu Oct 23 17:46:26 2014 +0200

dialog: break loop when profile entry doesn't exist

---

 modules/dialog/dlg_profile.c |   42 +++++++++++++++++++++---------------------
 1 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/modules/dialog/dlg_profile.c b/modules/dialog/dlg_profile.c
index 01f3c25..7e26e9c 100644
--- a/modules/dialog/dlg_profile.c
+++ b/modules/dialog/dlg_profile.c
@@ -375,33 +375,33 @@ int remove_profile(dlg_profile_table_t *profile, str *value, str *puid)
 	unsigned int hash;
 	struct dlg_profile_entry *p_entry;
 	struct dlg_profile_hash *lh;
-	struct dlg_profile_hash *kh;
 
 	hash = calc_hash_profile(value, puid, profile);
 	lock_get(&profile->lock );
 	p_entry = &profile->entries[hash];
 	lh = p_entry->first;
-	while(lh) {
-		kh = lh->next;
-		if(lh->dlg==NULL && lh->puid_len==puid->len
-				&& lh->value.len==value->len
-				&& strncmp(lh->puid, puid->s, puid->len)==0
-				&& strncmp(lh->value.s, value->s, value->len)==0) {
-			/* last element on the list? */
-			if (lh==lh->next) {
-				p_entry->first = NULL;
-			} else {
-				if (p_entry->first==lh)
-					p_entry->first = lh->next;
-				lh->next->prev = lh->prev;
-				lh->prev->next = lh->next;
+	if(lh) {
+		do {
+			if(lh->dlg==NULL && lh->puid_len==puid->len
+					&& lh->value.len==value->len
+					&& strncmp(lh->puid, puid->s, puid->len)==0
+					&& strncmp(lh->value.s, value->s, value->len)==0) {
+				/* last element on the list? */
+				if (lh==lh->next) {
+					p_entry->first = NULL;
+				} else {
+					if (p_entry->first==lh)
+						p_entry->first = lh->next;
+					lh->next->prev = lh->prev;
+					lh->prev->next = lh->next;
+				}
+				lh->next = lh->prev = NULL;
+				if(lh->linker) shm_free(lh->linker);
+				p_entry->content--;
+				return 1;
 			}
-			lh->next = lh->prev = NULL;
-			if(lh->linker) shm_free(lh->linker);
-			p_entry->content--;
-			return 1;
-		}
-		lh = kh;
+			lh = lh->next;
+		} while(lh != p_entry->first);
 	}
 	lock_release(&profile->lock );
 	return 0;




More information about the sr-dev mailing list