Fix allocation check to test the right variable
authorDaniel Gustafsson
Tue, 17 Jun 2025 20:42:38 +0000 (22:42 +0200)
committerDaniel Gustafsson
Tue, 17 Jun 2025 20:42:38 +0000 (22:42 +0200)
The memory allocation for cancelConn->be_cancel_key was accidentally
checking the be_cancel_key member in the conn object instead of the
one in cancelConn.

Author: Ranier Vilela 
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/CAEudQAq4ySDR6dsg9xwurBXwud02hX7XCOZZAcZx-JMn6A06nA@mail.gmail.com

src/interfaces/libpq/fe-cancel.c

index 8c7c198a53071025aea869d6707e1afeaf872b94..cd3102346bfa7800076c218e6e51954097eaf0a1 100644 (file)
@@ -114,7 +114,7 @@ PQcancelCreate(PGconn *conn)
    if (conn->be_cancel_key != NULL)
    {
        cancelConn->be_cancel_key = malloc(conn->be_cancel_key_len);
-       if (!conn->be_cancel_key)
+       if (cancelConn->be_cancel_key == NULL)
            goto oom_error;
        memcpy(cancelConn->be_cancel_key, conn->be_cancel_key, conn->be_cancel_key_len);
    }