From 6ff1bcfab046d82f70a1309b6ed4c7ccd6f167a9 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sat, 28 Jun 2014 21:04:35 +0300 Subject: [PATCH] Fix #257: Windows 7: SIPE crashes after a minute (II) I verified from the GLIB version history that before 2.30.0 destroy notifiers were called before the hash table entry was invalidated. In SIPE HTTP stack this can lead to race conditions. Updated the code accordingly. --- src/core/sipe-http-transport.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/core/sipe-http-transport.c b/src/core/sipe-http-transport.c index 7ea07bf8..7583015e 100644 --- a/src/core/sipe-http-transport.c +++ b/src/core/sipe-http-transport.c @@ -111,19 +111,15 @@ static void sipe_http_transport_drop(struct sipe_http *http, conn->host_port, message ? message : "REASON UNKNOWN"); - /* - * It seems that the value destroy function can be called *before* the - * entry is removed from the hash table. As it is possible that the user - * callback, triggered by sipe_http_transport_free(), generates a new - * HTTP request to the same host:port combination immediately, then - * sipe_http_transport_new() will find the *invalid* entry and try - * to re-establish the connection. This will lead to a crash as soon as - * the memory for the invalid entry will be freed. - * - * Therefore we don't use g_hash_table_remove() here. - */ +#if GLIB_CHECK_VERSION(2,30,0) + /* this triggers sipe_http_transport_free() */ + g_hash_table_remove(http->connections, conn->host_port); +#else + /* GLIB < 2.30 calls destroy notifiers *before* removing the entry */ + /* which can cause a race condition with sipe_http_transport_new() */ g_hash_table_steal(http->connections, conn->host_port); sipe_http_transport_free(conn); +#endif /* conn is no longer valid */ } -- 2.11.4.GIT