]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
asnyc-thrdd: explain how this is okay with a comment
authorStefan Eissing <stefan@eissing.org>
Fri, 16 May 2025 08:38:13 +0000 (10:38 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 16 May 2025 10:55:17 +0000 (12:55 +0200)
Coverity assess correctly that a variable write under mutex lock could
overwrite values from another thread - if the function were ever called
from multiple thread for the same transfer - which it is not.

Closes #17365

lib/asyn-thrdd.c

index a95c736b65eee6a7a350842c21a98dc7c319aca9..b71bd133da760fb916acd76c8dd7f2ffa4d30979 100644 (file)
@@ -318,11 +318,15 @@ static void async_thrdd_destroy(struct Curl_easy *data)
 
     /* Release our reference to the data shared with the thread. */
     Curl_mutex_acquire(&addr->mutx);
-    thrdd->addr = NULL;
     --addr->ref_count;
     CURL_TRC_DNS(data, "resolve, destroy async data, shared ref=%d",
                  addr->ref_count);
     done = !addr->ref_count;
+    /* we give up our reference to `addr`, so NULL our pointer.
+     * coverity analyses this as being a potential unsynched write,
+     * assuming two calls to this function could be invoked concurrently.
+     * Which they never are, as the transfer's side runs single-threaded. */
+    thrdd->addr = NULL;
     if(!done) {
       /* thread is still running. Detach the thread while mutexed, it will
        * trigger the cleanup when it releases its reference. */