mirror of
https://github.com/systemd/systemd
synced 2024-10-06 16:21:34 +00:00
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:
parent
49cce12d4a
commit
08f904fddc
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue