From: Yorgos Thessalonikefs Date: Mon, 29 Apr 2024 08:15:19 +0000 (+0200) Subject: - Cleanup unnecessary strdup calls for EDE strings. X-Git-Tag: release-1.20.0rc1~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=63a6b7b255baf018002990ae8a79330a6710282d;p=thirdparty%2Funbound.git - Cleanup unnecessary strdup calls for EDE strings. --- diff --git a/doc/Changelog b/doc/Changelog index 3f561f685..f51957575 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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 diff --git a/iterator/iterator.c b/iterator/iterator.c index 916d39900..5732a4148 100644 --- a/iterator/iterator.c +++ b/iterator/iterator.c @@ -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 */ diff --git a/services/mesh.c b/services/mesh.c index eb4315a49..55afd065f 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -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) { diff --git a/util/module.c b/util/module.c index 62e5de4a0..90a155b5e 100644 --- a/util/module.c +++ b/util/module.c @@ -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; diff --git a/util/module.h b/util/module.h index d54d56895..9020bfee9 100644 --- a/util/module.h +++ b/util/module.h @@ -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); diff --git a/validator/validator.c b/validator/validator.c index 15ae13a39..3cf291658 100644 --- a/validator/validator.c +++ b/validator/validator.c @@ -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); } } /*