|
|
8335b1 |
diff --git a/modules/aaa/mod_auth_digest.c b/modules/aaa/mod_auth_digest.c
|
|
|
8335b1 |
index 44b5fc8..6a50ba7 100644
|
|
|
8335b1 |
--- a/modules/aaa/mod_auth_digest.c
|
|
|
8335b1 |
+++ b/modules/aaa/mod_auth_digest.c
|
|
|
8335b1 |
@@ -261,6 +261,26 @@ static void log_error_and_cleanup(char *msg, apr_status_t sts, server_rec *s)
|
|
|
8335b1 |
cleanup_tables(NULL);
|
|
|
8335b1 |
}
|
|
|
8335b1 |
|
|
|
8335b1 |
+/* RMM helper functions that behave like single-step malloc/free. */
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+static void *rmm_malloc(apr_rmm_t *rmm, apr_size_t size)
|
|
|
8335b1 |
+{
|
|
|
8335b1 |
+ apr_rmm_off_t offset = apr_rmm_malloc(rmm, size);
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+ if (!offset) {
|
|
|
8335b1 |
+ return NULL;
|
|
|
8335b1 |
+ }
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+ return apr_rmm_addr_get(rmm, offset);
|
|
|
8335b1 |
+}
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+static apr_status_t rmm_free(apr_rmm_t *rmm, void *alloc)
|
|
|
8335b1 |
+{
|
|
|
8335b1 |
+ apr_rmm_off_t offset = apr_rmm_offset_get(rmm, alloc);
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+ return apr_rmm_free(rmm, offset);
|
|
|
8335b1 |
+}
|
|
|
8335b1 |
+
|
|
|
8335b1 |
#if APR_HAS_SHARED_MEMORY
|
|
|
8335b1 |
|
|
|
8335b1 |
static int initialize_tables(server_rec *s, apr_pool_t *ctx)
|
|
|
8335b1 |
@@ -299,8 +319,8 @@ static int initialize_tables(server_rec *s, apr_pool_t *ctx)
|
|
|
8335b1 |
return !OK;
|
|
|
8335b1 |
}
|
|
|
8335b1 |
|
|
|
8335b1 |
- client_list = apr_rmm_addr_get(client_rmm, apr_rmm_malloc(client_rmm, sizeof(*client_list) +
|
|
|
8335b1 |
- sizeof(client_entry*)*num_buckets));
|
|
|
8335b1 |
+ client_list = rmm_malloc(client_rmm, sizeof(*client_list) +
|
|
|
8335b1 |
+ sizeof(client_entry *) * num_buckets);
|
|
|
8335b1 |
if (!client_list) {
|
|
|
8335b1 |
log_error_and_cleanup("failed to allocate shared memory", -1, s);
|
|
|
8335b1 |
return !OK;
|
|
|
8335b1 |
@@ -322,7 +342,7 @@ static int initialize_tables(server_rec *s, apr_pool_t *ctx)
|
|
|
8335b1 |
|
|
|
8335b1 |
/* setup opaque */
|
|
|
8335b1 |
|
|
|
8335b1 |
- opaque_cntr = apr_rmm_addr_get(client_rmm, apr_rmm_malloc(client_rmm, sizeof(*opaque_cntr)));
|
|
|
8335b1 |
+ opaque_cntr = rmm_malloc(client_rmm, sizeof(*opaque_cntr));
|
|
|
8335b1 |
if (opaque_cntr == NULL) {
|
|
|
8335b1 |
log_error_and_cleanup("failed to allocate shared memory", -1, s);
|
|
|
8335b1 |
return !OK;
|
|
|
8335b1 |
@@ -339,7 +359,7 @@ static int initialize_tables(server_rec *s, apr_pool_t *ctx)
|
|
|
8335b1 |
|
|
|
8335b1 |
/* setup one-time-nonce counter */
|
|
|
8335b1 |
|
|
|
8335b1 |
- otn_counter = apr_rmm_addr_get(client_rmm, apr_rmm_malloc(client_rmm, sizeof(*otn_counter)));
|
|
|
8335b1 |
+ otn_counter = rmm_malloc(client_rmm, sizeof(*otn_counter));
|
|
|
8335b1 |
if (otn_counter == NULL) {
|
|
|
8335b1 |
log_error_and_cleanup("failed to allocate shared memory", -1, s);
|
|
|
8335b1 |
return !OK;
|
|
|
8335b1 |
@@ -779,7 +799,7 @@ static client_entry *get_client(unsigned long key, const request_rec *r)
|
|
|
8335b1 |
* last entry in each bucket and updates the counters. Returns the
|
|
|
8335b1 |
* number of removed entries.
|
|
|
8335b1 |
*/
|
|
|
8335b1 |
-static long gc(void)
|
|
|
8335b1 |
+static long gc(server_rec *s)
|
|
|
8335b1 |
{
|
|
|
8335b1 |
client_entry *entry, *prev;
|
|
|
8335b1 |
unsigned long num_removed = 0, idx;
|
|
|
8335b1 |
@@ -789,6 +809,12 @@ static long gc(void)
|
|
|
8335b1 |
for (idx = 0; idx < client_list->tbl_len; idx++) {
|
|
|
8335b1 |
entry = client_list->table[idx];
|
|
|
8335b1 |
prev = NULL;
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+ if (!entry) {
|
|
|
8335b1 |
+ /* This bucket is empty. */
|
|
|
8335b1 |
+ continue;
|
|
|
8335b1 |
+ }
|
|
|
8335b1 |
+
|
|
|
8335b1 |
while (entry->next) { /* find last entry */
|
|
|
8335b1 |
prev = entry;
|
|
|
8335b1 |
entry = entry->next;
|
|
|
8335b1 |
@@ -800,8 +826,16 @@ static long gc(void)
|
|
|
8335b1 |
client_list->table[idx] = NULL;
|
|
|
8335b1 |
}
|
|
|
8335b1 |
if (entry) { /* remove entry */
|
|
|
8335b1 |
- apr_rmm_free(client_rmm, apr_rmm_offset_get(client_rmm, entry));
|
|
|
8335b1 |
+ apr_status_t err;
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+ err = rmm_free(client_rmm, entry);
|
|
|
8335b1 |
num_removed++;
|
|
|
8335b1 |
+
|
|
|
8335b1 |
+ if (err) {
|
|
|
8335b1 |
+ /* Nothing we can really do but log... */
|
|
|
8335b1 |
+ ap_log_error(APLOG_MARK, APLOG_ERR, err, s, APLOGNO()
|
|
|
8335b1 |
+ "Failed to free auth_digest client allocation");
|
|
|
8335b1 |
+ }
|
|
|
8335b1 |
}
|
|
|
8335b1 |
}
|
|
|
8335b1 |
|
|
|
8335b1 |
@@ -835,16 +869,16 @@ static client_entry *add_client(unsigned long key, client_entry *info,
|
|
|
8335b1 |
|
|
|
8335b1 |
/* try to allocate a new entry */
|
|
|
8335b1 |
|
|
|
8335b1 |
- entry = apr_rmm_addr_get(client_rmm, apr_rmm_malloc(client_rmm, sizeof(client_entry)));
|
|
|
8335b1 |
+ entry = rmm_malloc(client_rmm, sizeof(client_entry));
|
|
|
8335b1 |
if (!entry) {
|
|
|
8335b1 |
- long num_removed = gc();
|
|
|
8335b1 |
+ long num_removed = gc(s);
|
|
|
8335b1 |
ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO(01766)
|
|
|
8335b1 |
"gc'd %ld client entries. Total new clients: "
|
|
|
8335b1 |
"%ld; Total removed clients: %ld; Total renewed clients: "
|
|
|
8335b1 |
"%ld", num_removed,
|
|
|
8335b1 |
client_list->num_created - client_list->num_renewed,
|
|
|
8335b1 |
client_list->num_removed, client_list->num_renewed);
|
|
|
8335b1 |
- entry = apr_rmm_addr_get(client_rmm, apr_rmm_malloc(client_rmm, sizeof(client_entry)));
|
|
|
8335b1 |
+ entry = rmm_malloc(client_rmm, sizeof(client_entry));
|
|
|
8335b1 |
if (!entry) {
|
|
|
8335b1 |
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s, APLOGNO(01767)
|
|
|
8335b1 |
"unable to allocate new auth_digest client");
|
|
|
8335b1 |
|