summaryrefslogtreecommitdiff
path: root/src/resolve
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-12-26 12:36:24 +0100
committerLennart Poettering <lennart@poettering.net>2015-12-26 19:09:11 +0100
commit08f904fddc163ccf9524218cd900a89716ee4a63 (patch)
tree70c2da2cf0e561808dc466a19193d760aec6cff4 /src/resolve
parent49cce12d4a07a77c6321b743e538c648d33c037c (diff)
resolved: don't unnecessarily allocate memory in dns_packet_append_name()
When compression support is off, there's no point in duplicating the name string. Hence, don't do it.
Diffstat (limited to 'src/resolve')
-rw-r--r--src/resolve/resolved-dns-packet.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index 7908d0bcf5..c425b89034 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -499,7 +499,7 @@ int dns_packet_append_name(
saved_size = p->size;
while (*name) {
- _cleanup_free_ char *s = NULL;
+ const char *z = name;
char label[DNS_LABEL_MAX];
size_t n = 0;
int k;
@@ -518,12 +518,6 @@ int dns_packet_append_name(
}
}
- s = strdup(name);
- if (!s) {
- r = -ENOMEM;
- goto fail;
- }
-
r = dns_label_unescape(&name, label, sizeof(label));
if (r < 0)
goto fail;
@@ -544,6 +538,14 @@ int dns_packet_append_name(
goto fail;
if (allow_compression) {
+ _cleanup_free_ char *s = NULL;
+
+ s = strdup(z);
+ if (!s) {
+ r = -ENOMEM;
+ goto fail;
+ }
+
r = hashmap_ensure_allocated(&p->names, &dns_name_hash_ops);
if (r < 0)
goto fail;