Module: kamailio
Branch: master
Commit: d0fc93546dcfb160716369bf04f058cac32dec5c
URL: 
https://github.com/kamailio/kamailio/commit/d0fc93546dcfb160716369bf04f058cac32dec5c

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-07-18T09:34:33+02:00

core: dns cache - destroy new entry only when lot linked to the list

---

Modified: src/core/dns_cache.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/d0fc93546dcfb160716369bf04f058cac32dec5c.diff
Patch: 
https://github.com/kamailio/kamailio/commit/d0fc93546dcfb160716369bf04f058cac32dec5c.patch

---

diff --git a/src/core/dns_cache.c b/src/core/dns_cache.c
index cb343a81184..9ea774705ee 100644
--- a/src/core/dns_cache.c
+++ b/src/core/dns_cache.c
@@ -1928,11 +1928,13 @@ inline static struct dns_hash_entry 
*dns_cache_do_request(str *name, int type)
                                        }
                                }
                                if(add_record) {
-                                       dns_cache_add_unsafe(r); /* refcnt++ 
inside */
-                                       if(atomic_get(&r->refcnt) == 0) {
-                                               /* if cache adding failed and 
nobody else is interested
-                                                * destroy this entry */
-                                               dns_destroy_entry(r);
+                                       if(dns_cache_add_unsafe(r) < 0) {
+                                               /* refcnt++ inside */
+                                               if(atomic_get(&r->refcnt) <= 0) 
{
+                                                       /* if cache adding 
failed and nobody else is interested
+                                                        * destroy this entry */
+                                                       dns_destroy_entry(r);
+                                               }
                                        }
                                        if(old) {
                                                _dns_hash_remove(old);
@@ -2034,11 +2036,13 @@ inline static struct dns_hash_entry 
*dns_cache_do_request(str *name, int type)
                                }
                        }
                        if(add_record) {
-                               dns_cache_add_unsafe(r); /* refcnt++ inside */
-                               if(atomic_get(&r->refcnt) == 0) {
-                                       /* if cache adding failed and nobody 
else is interested
-                                        * destroy this entry */
-                                       dns_destroy_entry(r);
+                               if(dns_cache_add_unsafe(r) < 0) {
+                                       /* refcnt++ inside */
+                                       if(atomic_get(&r->refcnt) <= 0) {
+                                               /* if cache adding failed and 
nobody else is interested
+                                                * destroy this entry */
+                                               dns_destroy_entry(r);
+                                       }
                                }
                                if(old) {
                                        _dns_hash_remove(old);

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to