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:
Lennart Poettering
2015-12-26 19:09:10 +01:00
parent 0936416a1c
commit 7b50eb2efa
8 changed files with 73 additions and 94 deletions
+4 -4
View File
@@ -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;
}