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.
This commit is contained in:
Lennart Poettering 2015-12-26 12:36:24 +01:00
parent 49cce12d4a
commit 08f904fddc

View file

@ -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;