From: Vsevolod Stakhov Date: Wed, 29 Jun 2016 13:43:17 +0000 (+0100) Subject: [Minor] Add more debugging possibilites for maps code X-Git-Tag: 1.3.0~219 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fd6081d60ef0102e40681fe3362c48ee472e03fa;p=rspamd.git [Minor] Add more debugging possibilites for maps code --- diff --git a/src/libutil/map.c b/src/libutil/map.c index 7731cfea9..0a73d4c72 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -38,18 +38,18 @@ #undef MAP_DEBUG_REFS #ifdef MAP_DEBUG_REFS -#define MAP_RETAIN(x) do { \ - msg_err ("retain ref %p, refcount: %d -> %d", (x), (x)->ref.refcount, (x)->ref.refcount + 1); \ +#define MAP_RETAIN(x, t) do { \ + msg_err (G_GNUC_PRETTY_FUNCTION ": " t ": retain ref %p, refcount: %d -> %d", (x), (x)->ref.refcount, (x)->ref.refcount + 1); \ REF_RETAIN(x); \ } while (0) -#define MAP_RELEASE(x) do { \ - msg_err ("release ref %p, refcount: %d -> %d", (x), (x)->ref.refcount, (x)->ref.refcount - 1); \ +#define MAP_RELEASE(x, t) do { \ + msg_err (G_GNUC_PRETTY_FUNCTION ": " t ": release ref %p, refcount: %d -> %d", (x), (x)->ref.refcount, (x)->ref.refcount - 1); \ REF_RELEASE(x); \ } while (0) #else -#define MAP_RETAIN REF_RETAIN -#define MAP_RELEASE REF_RELEASE +#define MAP_RETAIN(x, t) REF_RETAIN(x) +#define MAP_RELEASE(x, t) REF_RELEASE(x) #endif static const gchar *hash_fill = "1"; @@ -119,7 +119,7 @@ write_http_request (struct http_callback_data *cbd) rspamd_http_connection_write_message (cbd->conn, msg, cbd->data->host, NULL, cbd, cbd->fd, &cbd->tv, cbd->ev_base); - MAP_RETAIN (cbd); + MAP_RETAIN (cbd, "http_callback_data"); } else { msg_err_map ("cannot connect to %s: %s", cbd->data->host, @@ -271,8 +271,8 @@ free_http_cbdata_common (struct http_callback_data *cbd, gboolean plan_new) rspamd_inet_address_destroy (cbd->addr); } - MAP_RELEASE (cbd->bk); - MAP_RELEASE (periodic); + MAP_RELEASE (cbd->bk, "rspamd_map_backend"); + MAP_RELEASE (periodic, "periodic"); g_slice_free1 (sizeof (struct http_callback_data), cbd); } @@ -310,7 +310,7 @@ http_map_error (struct rspamd_http_connection *conn, cbd->periodic->errored = TRUE; msg_err_map ("connection with http server terminated incorrectly: %e", err); rspamd_map_periodic_callback (-1, EV_TIMEOUT, cbd->periodic); - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); } static void @@ -319,7 +319,7 @@ rspamd_map_cache_cb (gint fd, short what, gpointer ud) struct rspamd_http_map_cached_cbdata *cache_cbd = ud; g_atomic_int_set (&cache_cbd->map->cache->available, 0); - REF_RELEASE (cache_cbd->shm); + MAP_RELEASE (cache_cbd->shm, "rspamd_http_map_cached_cbdata"); event_del (&cache_cbd->timeout); g_slice_free1 (sizeof (*cache_cbd), cache_cbd); } @@ -344,7 +344,7 @@ http_map_finish (struct rspamd_http_connection *conn, /* Reset the whole chain */ cbd->periodic->cur_backend = 0; rspamd_map_periodic_callback (-1, EV_TIMEOUT, cbd->periodic); - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); return 0; } @@ -373,7 +373,7 @@ http_map_finish (struct rspamd_http_connection *conn, cbd->data_len = msg->body_buf.len; rspamd_http_connection_reset (cbd->conn); write_http_request (cbd); - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); return 0; } @@ -419,7 +419,7 @@ http_map_finish (struct rspamd_http_connection *conn, cbd->stage = map_load_signature; rspamd_http_connection_reset (cbd->conn); write_http_request (cbd); - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); return 0; } @@ -494,7 +494,7 @@ read_data: cache_cbd = g_slice_alloc0 (sizeof (*cache_cbd)); cache_cbd->shm = cbd->shmem_data; cache_cbd->map = map; - REF_RETAIN (cache_cbd->shm); + MAP_RETAIN (cache_cbd->shm, "shmem_data"); event_set (&cache_cbd->timeout, -1, EV_TIMEOUT, rspamd_map_cache_cb, cache_cbd); event_base_set (cbd->ev_base, &cache_cbd->timeout); @@ -525,13 +525,13 @@ read_data: bk->uri, cbd->data->host, msg->code); } - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); return 0; err: cbd->periodic->errored = 1; rspamd_map_periodic_callback (-1, EV_TIMEOUT, cbd->periodic); - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); return 0; } @@ -703,7 +703,7 @@ rspamd_map_dns_callback (struct rdns_reply *reply, void *arg) } } - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); } static gboolean @@ -774,9 +774,9 @@ rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backe cbd->fd = -1; cbd->check = check; cbd->periodic = periodic; - MAP_RETAIN (periodic); + MAP_RETAIN (periodic, "periodic"); cbd->bk = bk; - MAP_RETAIN (bk); + MAP_RETAIN (bk, "rspamd_map_backend"); cbd->stage = map_resolve_host2; double_to_tv (map->cfg->map_timeout, &cbd->tv); REF_INIT_RETAIN (cbd, free_http_cbdata); @@ -788,12 +788,12 @@ rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backe if (rdns_make_request_full (map->r->r, rspamd_map_dns_callback, cbd, map->cfg->dns_timeout, map->cfg->dns_retransmits, 1, data->host, RDNS_REQUEST_A)) { - MAP_RETAIN (cbd); + MAP_RETAIN (cbd, "http_callback_data"); } if (rdns_make_request_full (map->r->r, rspamd_map_dns_callback, cbd, map->cfg->dns_timeout, map->cfg->dns_retransmits, 1, data->host, RDNS_REQUEST_AAAA)) { - MAP_RETAIN (cbd); + MAP_RETAIN (cbd, "http_callback_data"); } map->dtor = free_http_cbdata_dtor; @@ -805,7 +805,7 @@ rspamd_map_common_http_callback (struct rspamd_map *map, struct rspamd_map_backe } /* We don't need own ref as it is now ref counted by DNS handlers */ - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "http_callback_data"); } static void @@ -900,7 +900,7 @@ rspamd_map_periodic_callback (gint fd, short what, void *ud) /* We should not check other backends if some backend has failed */ rspamd_map_schedule_periodic (cbd->map, FALSE, FALSE, TRUE); g_atomic_int_set (cbd->map->locked, 0); - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "periodic"); return; } @@ -908,7 +908,7 @@ rspamd_map_periodic_callback (gint fd, short what, void *ud) /* For each backend we need to check for modifications */ if (cbd->cur_backend >= cbd->map->backends->len) { /* Last backend */ - MAP_RELEASE (cbd); + MAP_RELEASE (cbd, "periodic"); return; } @@ -978,7 +978,7 @@ rspamd_map_remove_all (struct rspamd_config *cfg) for (i = 0; i < map->backends->len; i ++) { bk = g_ptr_array_index (map->backends, i); - MAP_RELEASE (bk); + MAP_RELEASE (bk, "rspamd_map_backend"); } if (map->dtor) { @@ -1199,7 +1199,7 @@ rspamd_map_parse_backend (struct rspamd_config *cfg, const gchar *map_line) return bk; err: - MAP_RELEASE (bk); + MAP_RELEASE (bk, "rspamd_map_backend"); if (hdata) { g_slice_free1 (sizeof (*hdata), hdata);