comparison util.c @ 453:d55cc0b73c62

Merge nn_user_free_list() into a parent function.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 26 May 2012 05:16:16 +0300
parents aeb3171f9e28
children 35d67bd0613b
comparison
equal deleted inserted replaced
452:aeb3171f9e28 453:d55cc0b73c62
440 th_free(user->name); 440 th_free(user->name);
441 th_free(user); 441 th_free(user);
442 } 442 }
443 443
444 444
445 static void nn_user_free_list(nn_user_t *list)
446 {
447 nn_user_t *next, *curr = list;
448
449 while (curr != NULL)
450 {
451 next = curr->next;
452 nn_user_free(curr);
453 curr = next;
454 }
455 }
456
457
458 nn_user_t *nn_userhash_foreach(const nn_userhash_t *list, int (*func)(const nn_user_t *)) 445 nn_user_t *nn_userhash_foreach(const nn_userhash_t *list, int (*func)(const nn_user_t *))
459 { 446 {
460 int i; 447 int i;
461 448
462 if (list == NULL) return NULL; 449 if (list == NULL) return NULL;
628 if (hash == NULL) 615 if (hash == NULL)
629 return; 616 return;
630 617
631 for (i = 0; i < NN_NUM_BUCKETS; i++) 618 for (i = 0; i < NN_NUM_BUCKETS; i++)
632 { 619 {
633 nn_user_free_list(hash->buckets[i]); 620 nn_user_t *curr = hash->buckets[i];
621
622 while (curr != NULL)
623 {
624 nn_user_t *next = curr->next;
625 nn_user_free(curr);
626 curr = next;
627 }
628
634 hash->buckets[i] = NULL; 629 hash->buckets[i] = NULL;
635 } 630 }
636 631
637 th_free(hash); 632 th_free(hash);
638 } 633 }