]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Cleanup unnecessary strdup calls for EDE strings.
authorYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Mon, 29 Apr 2024 08:15:19 +0000 (10:15 +0200)
committerYorgos Thessalonikefs <yorgos@nlnetlabs.nl>
Mon, 29 Apr 2024 08:15:19 +0000 (10:15 +0200)
doc/Changelog
iterator/iterator.c
services/mesh.c
util/module.c
util/module.h
validator/validator.c

index 3f561f685af735b10cab6ea5471cf3ea9566926b..f519575758cecc774dc16c85ad3933759bf521b7 100644 (file)
@@ -1,3 +1,6 @@
+29 April 2024: Yorgos
+       - Cleanup unnecessary strdup calls for EDE strings.
+
 26 April 2024: Wouter
        - Fix cachedb with serve-expired-client-timeout disabled. The edns
          subnet module deletes global cache and cachedb cache when it
index 916d399008cffffa8afe0289d92bae7c130330bf..5732a414857e7f4876075bee6757de2870e61b05 100644 (file)
@@ -4045,17 +4045,9 @@ processFinished(struct module_qstate* qstate, struct iter_qstate* iq,
                !qstate->env->cfg->val_log_squelch) {
                char* err_str = errinf_to_str_misc(qstate);
                if(err_str) {
-                       size_t err_str_len = strlen(err_str);
                        verbose(VERB_ALGO, "iterator EDE: %s", err_str);
-                       /* allocate space and store the error
-                        * string */
-                       iq->response->rep->reason_bogus_str = regional_alloc(
-                               qstate->region,
-                               sizeof(char) * (err_str_len+1));
-                       memcpy(iq->response->rep->reason_bogus_str,
-                               err_str, err_str_len+1);
+                       iq->response->rep->reason_bogus_str = err_str;
                }
-               free(err_str);
        }
 
        /* we have finished processing this query */
index eb4315a495bb0e82c1648a1e00e632882719d5a3..55afd065f291a0aa3587f0d7262c676fac1daad0 100644 (file)
@@ -1202,7 +1202,7 @@ mesh_do_callback(struct mesh_state* m, int rcode, struct reply_info* rep,
                rcode = LDNS_RCODE_SERVFAIL;
        if(!rcode && rep && (rep->security == sec_status_bogus ||
                rep->security == sec_status_secure_sentinel_fail)) {
-               if(!(reason = errinf_to_str_bogus(&m->s)))
+               if(!(reason = errinf_to_str_bogus(&m->s, NULL)))
                        rcode = LDNS_RCODE_SERVFAIL;
        }
        /* send the reply */
@@ -1487,9 +1487,7 @@ void mesh_query_done(struct mesh_state* mstate)
                && mstate->s.env->cfg->log_servfail
                && !mstate->s.env->cfg->val_log_squelch) {
                        char* err = errinf_to_str_servfail(&mstate->s);
-                       if(err)
-                               log_err("%s", err);
-                       free(err);
+                       if(err) { log_err("%s", err); }
                }
        }
        for(r = mstate->reply_list; r; r = r->next) {
index 62e5de4a05bbc106d338319d394f0bbd2942c898..90a155b5e8aa06a6370e88efcfeff163ebf3e67f 100644 (file)
@@ -129,7 +129,7 @@ void errinf_origin(struct module_qstate* qstate, struct sock_list *origin)
        }
 }
 
-char* errinf_to_str_bogus(struct module_qstate* qstate)
+char* errinf_to_str_bogus(struct module_qstate* qstate, struct regional* region)
 {
        char buf[20480];
        char* p = buf;
@@ -148,7 +148,10 @@ char* errinf_to_str_bogus(struct module_qstate* qstate)
                snprintf(p, left, " %s", s->str);
                left -= strlen(p); p += strlen(p);
        }
-       p = strdup(buf);
+       if(region)
+               p = regional_strdup(region, buf);
+       else
+               p = strdup(buf);
        if(!p)
                log_err("malloc failure in errinf_to_str");
        return p;
@@ -188,7 +191,7 @@ char* errinf_to_str_servfail(struct module_qstate* qstate)
                snprintf(p, left, " %s", s->str);
                left -= strlen(p); p += strlen(p);
        }
-       p = strdup(buf);
+       p = regional_strdup(qstate->region, buf);
        if(!p)
                log_err("malloc failure in errinf_to_str");
        return p;
@@ -206,7 +209,7 @@ char* errinf_to_str_misc(struct module_qstate* qstate)
                snprintf(p, left, "%s%s", (s==qstate->errinf?"":" "), s->str);
                left -= strlen(p); p += strlen(p);
        }
-       p = strdup(buf);
+       p = regional_strdup(qstate->region, buf);
        if(!p)
                log_err("malloc failure in errinf_to_str");
        return p;
index d54d56895ff38722a0951f11b9be296927f16ec8..9020bfee9cb9359ed635f891e895dd2ba7919bed 100644 (file)
@@ -832,9 +832,9 @@ void errinf_dname(struct module_qstate* qstate, const char* str,
  * Create error info in string.  For validation failures.
  * @param qstate: query state.
  * @return string or NULL on malloc failure (already logged).
- *    This string is malloced and has to be freed by caller.
+ *    This string is malloced if region is NULL and has to be freed by caller.
  */
-char* errinf_to_str_bogus(struct module_qstate* qstate);
+char* errinf_to_str_bogus(struct module_qstate* qstate, struct regional* region);
 
 /**
  * Check the sldns_ede_code of the qstate->errinf.
@@ -847,7 +847,6 @@ sldns_ede_code errinf_to_reason_bogus(struct module_qstate* qstate);
  * Create error info in string.  For other servfails.
  * @param qstate: query state.
  * @return string or NULL on malloc failure (already logged).
- *    This string is malloced and has to be freed by caller.
  */
 char* errinf_to_str_servfail(struct module_qstate* qstate);
 
@@ -855,7 +854,6 @@ char* errinf_to_str_servfail(struct module_qstate* qstate);
  * Create error info in string.  For misc failures that are not servfail.
  * @param qstate: query state.
  * @return string or NULL on malloc failure (already logged).
- *    This string is malloced and has to be freed by caller.
  */
 char* errinf_to_str_misc(struct module_qstate* qstate);
 
index 15ae13a39d04af8abfec94b27eb50e88e64c9ce8..3cf291658e715cc1c747caa76b687bd4ac14fa8d 100644 (file)
@@ -2453,19 +2453,12 @@ processFinished(struct module_qstate* qstate, struct val_qstate* vq,
                                log_query_info(NO_VERBOSE, "validation failure",
                                        &qstate->qinfo);
                        else {
-                               char* err_str = errinf_to_str_bogus(qstate);
+                               char* err_str = errinf_to_str_bogus(qstate,
+                                       qstate->region);
                                if(err_str) {
-                                       size_t err_str_len = strlen(err_str);
                                        log_info("%s", err_str);
-                                       /* allocate space and store the error
-                                        * string */
-                                       vq->orig_msg->rep->reason_bogus_str = regional_alloc(
-                                               qstate->region,
-                                               sizeof(char) * (err_str_len+1));
-                                       memcpy(vq->orig_msg->rep->reason_bogus_str,
-                                               err_str, err_str_len+1);
+                                       vq->orig_msg->rep->reason_bogus_str = err_str;
                                }
-                               free(err_str);
                        }
                }
                /*