Browse code

dialog: break loop when profile entry doesn't exist

(cherry picked from commit a65a212c1e7587182f113a94f3d0d8b46c97baa0)

Alex Hermann authored on 23/10/2014 15:46:26
Showing 1 changed files
... ...
@@ -375,33 +375,33 @@ int remove_profile(dlg_profile_table_t *profile, str *value, str *puid)
375 375
 	unsigned int hash;
376 376
 	struct dlg_profile_entry *p_entry;
377 377
 	struct dlg_profile_hash *lh;
378
-	struct dlg_profile_hash *kh;
379 378
 
380 379
 	hash = calc_hash_profile(value, puid, profile);
381 380
 	lock_get(&profile->lock );
382 381
 	p_entry = &profile->entries[hash];
383 382
 	lh = p_entry->first;
384
-	while(lh) {
385
-		kh = lh->next;
386
-		if(lh->dlg==NULL && lh->puid_len==puid->len
387
-				&& lh->value.len==value->len
388
-				&& strncmp(lh->puid, puid->s, puid->len)==0
389
-				&& strncmp(lh->value.s, value->s, value->len)==0) {
390
-			/* last element on the list? */
391
-			if (lh==lh->next) {
392
-				p_entry->first = NULL;
393
-			} else {
394
-				if (p_entry->first==lh)
395
-					p_entry->first = lh->next;
396
-				lh->next->prev = lh->prev;
397
-				lh->prev->next = lh->next;
383
+	if(lh) {
384
+		do {
385
+			if(lh->dlg==NULL && lh->puid_len==puid->len
386
+					&& lh->value.len==value->len
387
+					&& strncmp(lh->puid, puid->s, puid->len)==0
388
+					&& strncmp(lh->value.s, value->s, value->len)==0) {
389
+				/* last element on the list? */
390
+				if (lh==lh->next) {
391
+					p_entry->first = NULL;
392
+				} else {
393
+					if (p_entry->first==lh)
394
+						p_entry->first = lh->next;
395
+					lh->next->prev = lh->prev;
396
+					lh->prev->next = lh->next;
397
+				}
398
+				lh->next = lh->prev = NULL;
399
+				if(lh->linker) shm_free(lh->linker);
400
+				p_entry->content--;
401
+				return 1;
398 402
 			}
399
-			lh->next = lh->prev = NULL;
400
-			if(lh->linker) shm_free(lh->linker);
401
-			p_entry->content--;
402
-			return 1;
403
-		}
404
-		lh = kh;
403
+			lh = lh->next;
404
+		} while(lh != p_entry->first);
405 405
 	}
406 406
 	lock_release(&profile->lock );
407 407
 	return 0;