asnyc-thrdd: explain how this is okay with a comment

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
This commit is contained in:
Stefan Eissing 2025-05-16 10:38:13 +02:00 committed by Daniel Stenberg
parent 96726af95a
commit 73b8912580
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -318,11 +318,15 @@ static void async_thrdd_destroy(struct Curl_easy *data)
/* Release our reference to the data shared with the thread. */ /* Release our reference to the data shared with the thread. */
Curl_mutex_acquire(&addr->mutx); Curl_mutex_acquire(&addr->mutx);
thrdd->addr = NULL;
--addr->ref_count; --addr->ref_count;
CURL_TRC_DNS(data, "resolve, destroy async data, shared ref=%d", CURL_TRC_DNS(data, "resolve, destroy async data, shared ref=%d",
addr->ref_count); addr->ref_count);
done = !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) { if(!done) {
/* thread is still running. Detach the thread while mutexed, it will /* thread is still running. Detach the thread while mutexed, it will
* trigger the cleanup when it releases its reference. */ * trigger the cleanup when it releases its reference. */