]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http_server_connection_unref() now always sets *conn=NULL
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 22 Feb 2016 19:15:37 +0000 (21:15 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 22 Feb 2016 19:15:37 +0000 (21:15 +0200)
This makes its behavior consistent with other APIs in Dovecot.

src/lib-http/http-server-connection.c
src/lib-http/http-server.h

index 847f80c62e9be99cefdd5237c72809f7c054a6e2..e39135b615c0a8b5ef248dd228149d322b0323da 100644 (file)
@@ -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,
index 8fc1dd06c8bae0f313eca4a2cd9c92117eab7e5c..b90a39673127917159e0a8af63b32ca10da237c6 100644 (file)
@@ -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 *