From: Timo Sirainen Date: Mon, 22 Feb 2016 19:15:37 +0000 (+0200) Subject: lib-http: http_server_connection_unref() now always sets *conn=NULL X-Git-Tag: 2.2.22.rc1~99 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=702ebfdbd78702e3464b5804c8a7c83c9990ae96;p=thirdparty%2Fdovecot%2Fcore.git lib-http: http_server_connection_unref() now always sets *conn=NULL This makes its behavior consistent with other APIs in Dovecot. --- diff --git a/src/lib-http/http-server-connection.c b/src/lib-http/http-server-connection.c index 847f80c62e..e39135b615 100644 --- a/src/lib-http/http-server-connection.c +++ b/src/lib-http/http-server-connection.c @@ -21,6 +21,9 @@ static void http_server_connection_disconnect(struct http_server_connection *conn, const char *reason); +static bool +http_server_connection_unref_is_closed(struct http_server_connection *conn); + /* * Logging */ @@ -563,8 +566,7 @@ static void http_server_connection_input(struct connection *_conn) req = http_server_request_new(conn); } - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) { + if (http_server_connection_unref_is_closed(conn)) { /* connection got closed */ return; } @@ -607,8 +609,7 @@ static void http_server_connection_input(struct connection *_conn) i_unreached(); } - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) { + if (http_server_connection_unref_is_closed(conn)) { /* connection got closed */ return; } @@ -715,10 +716,7 @@ int http_server_connection_discard_payload( /* check whether connection is still viable */ http_server_connection_ref(conn); (void)http_server_connection_check_input(conn); - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) - return -1; - return 0; + return http_server_connection_unref_is_closed(conn) ? -1 : 0; } void http_server_connection_write_failed(struct http_server_connection *conn, @@ -817,8 +815,7 @@ static int http_server_connection_send_responses( blocks again, or the connection is closed */ while (!conn->closed && http_server_connection_next_response(conn)); - http_server_connection_unref(&conn); - if (conn == NULL || conn->closed) + if (http_server_connection_unref_is_closed(conn)) return -1; /* accept more requests if possible */ @@ -1025,13 +1022,15 @@ http_server_connection_disconnect(struct http_server_connection *conn, connection_disconnect(&conn->conn); } -void http_server_connection_unref(struct http_server_connection **_conn) +bool http_server_connection_unref(struct http_server_connection **_conn) { struct http_server_connection *conn = *_conn; i_assert(conn->refcount > 0); + + *_conn = NULL; if (--conn->refcount > 0) - return; + return TRUE; http_server_connection_disconnect(conn, NULL); @@ -1049,7 +1048,17 @@ void http_server_connection_unref(struct http_server_connection **_conn) i_free(conn->disconnect_reason); i_free(conn); - *_conn = NULL; + return FALSE; +} + +static bool +http_server_connection_unref_is_closed(struct http_server_connection *conn) +{ + bool closed = conn->closed; + + if (!http_server_connection_unref(&conn)) + closed = TRUE; + return closed; } void http_server_connection_close(struct http_server_connection **_conn, diff --git a/src/lib-http/http-server.h b/src/lib-http/http-server.h index 8fc1dd06c8..b90a396731 100644 --- a/src/lib-http/http-server.h +++ b/src/lib-http/http-server.h @@ -74,7 +74,8 @@ http_server_connection_create(struct http_server *server, int fd_in, int fd_out, bool ssl, const struct http_server_callbacks *callbacks, void *context); void http_server_connection_ref(struct http_server_connection *conn); -void http_server_connection_unref(struct http_server_connection **_conn); +/* Returns FALSE if unrefing destroyed the connection entirely */ +bool http_server_connection_unref(struct http_server_connection **_conn); void http_server_connection_close(struct http_server_connection **_conn, const char *reason); const struct http_server_stats *