From 93f9da6e0a9e701e4532056754c2d867e86d8dd6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 27 Nov 2017 12:01:41 +0000 Subject: [PATCH] networkd: plug some memleaks in rule serialization/deserialization This fixes the (mostly theoretical, since we're only parsing data that we write ourselves) memleak when iif or oif is deserialized multiple times. Unfortunately it does not fix the memleak when rule is freed, but that'll require a bigger effort. --- src/network/networkd-routing-policy-rule.c | 7 +++---- src/network/test-routing-policy-rule.c | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 20f748944ea..f4b3b7180b6 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1017,13 +1017,12 @@ int routing_policy_load_rules(const char *state_file, Set **rules) { } } else if (streq(a, "iif")) { - rule->iif = strdup(b); - if (!rule->iif) + if (free_and_strdup(&rule->iif, b) < 0) return log_oom(); + } else if (streq(a, "oif")) { - rule->oif = strdup(b); - if (!rule->oif) + if (free_and_strdup(&rule->oif, b) < 0) return log_oom(); } } diff --git a/src/network/test-routing-policy-rule.c b/src/network/test-routing-policy-rule.c index c619dbc1594..fc6eb5626d0 100644 --- a/src/network/test-routing-policy-rule.c +++ b/src/network/test-routing-policy-rule.c @@ -96,5 +96,9 @@ int main(int argc, char **argv) { test_rule_serialization("outgoing interface", "RULE=from=1::2/64 to=2::3/64 oif=eth0 table=1", NULL); + test_rule_serialization("freeing interface names", + "RULE=from=1::2/64 to=2::3/64 iif=e0 iif=e1 oif=e0 oif=e1 table=1", + "RULE=from=1::2/64 to=2::3/64 iif=e1 oif=e1 table=1"); + return 0; } -- 2.47.3