resolved: internalize string buffer of dns_resource_record_to_string()
Let's simplify usage and memory management of DnsResourceRecord's dns_resource_record_to_string() call: cache the formatted string as part of the object, and return it on subsequent calls, freeing it when the DnsResourceRecord itself is freed.
This commit is contained in:
@@ -657,18 +657,18 @@ int dns_answer_reserve_or_clone(DnsAnswer **a, unsigned n_free) {
|
||||
void dns_answer_dump(DnsAnswer *answer, FILE *f) {
|
||||
DnsResourceRecord *rr;
|
||||
DnsAnswerFlags flags;
|
||||
int ifindex, r;
|
||||
int ifindex;
|
||||
|
||||
if (!f)
|
||||
f = stdout;
|
||||
|
||||
DNS_ANSWER_FOREACH_FULL(rr, ifindex, flags, answer) {
|
||||
_cleanup_free_ char *t = NULL;
|
||||
const char *t;
|
||||
|
||||
fputc('\t', f);
|
||||
|
||||
r = dns_resource_record_to_string(rr, &t);
|
||||
if (r < 0) {
|
||||
t = dns_resource_record_to_string(rr);
|
||||
if (!t) {
|
||||
log_oom();
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user