* Add a new client to the list. Returns the entry if successful, NULL * otherwise. This triggers the garbage collection if memory is low. */
| 864 | * otherwise. This triggers the garbage collection if memory is low. |
| 865 | */ |
| 866 | static client_entry *add_client(unsigned long key, client_entry *info, |
| 867 | server_rec *s) |
| 868 | { |
| 869 | int bucket; |
| 870 | client_entry *entry; |
| 871 | |
| 872 | |
| 873 | if (!key || !client_shm) { |
| 874 | return NULL; |
| 875 | } |
| 876 | |
| 877 | bucket = key % client_list->tbl_len; |
| 878 | |
| 879 | apr_global_mutex_lock(client_lock); |
| 880 | |
| 881 | /* try to allocate a new entry */ |
| 882 | |
| 883 | entry = rmm_malloc(client_rmm, sizeof(client_entry)); |
| 884 | if (!entry) { |
| 885 | long num_removed = gc(s); |
| 886 | ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(01766) |
| 887 | "gc'd %ld client entries. Total new clients: " |
| 888 | "%ld; Total removed clients: %ld; Total renewed clients: " |
| 889 | "%ld", num_removed, |
| 890 | client_list->num_created - client_list->num_renewed, |
| 891 | client_list->num_removed, client_list->num_renewed); |
| 892 | entry = rmm_malloc(client_rmm, sizeof(client_entry)); |
| 893 | if (!entry) { |
| 894 | ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(01767) |
| 895 | "unable to allocate new auth_digest client"); |
| 896 | apr_global_mutex_unlock(client_lock); |
| 897 | return NULL; /* give up */ |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | /* now add the entry */ |
| 902 | |
| 903 | memcpy(entry, info, sizeof(client_entry)); |
| 904 | entry->key = key; |
| 905 | entry->next = client_list->table[bucket]; |
| 906 | client_list->table[bucket] = entry; |
| 907 | client_list->num_created++; |
| 908 | client_list->num_entries++; |
| 909 | |
| 910 | apr_global_mutex_unlock(client_lock); |
| 911 | |
| 912 | ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, APLOGNO(01768) |
| 913 | "allocated new client %lu", key); |
| 914 | |
| 915 | return entry; |
| 916 | } |
| 917 | |
| 918 | |
| 919 | /* |
no test coverage detected