richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
ac3a84
From 44d34632660f8456b7ca09510ed1b469541fac65 Mon Sep 17 00:00:00 2001
ac3a84
From: Yu Watanabe <watanabe.yu+github@gmail.com>
ac3a84
Date: Mon, 16 Jan 2023 22:07:06 +0900
ac3a84
Subject: [PATCH] network: fix memleak
ac3a84
ac3a84
Fixes a bug introduced by af2aea8bb64b0dc42ecbe5549216eb567681a803.
ac3a84
ac3a84
Fixes #25883 and #25891.
ac3a84
ac3a84
(cherry picked from commit 303dfa73b389e8f6dc58954e867c21724c1446f7)
ac3a84
ac3a84
Related: #2138081
ac3a84
---
ac3a84
 src/network/networkd-address.c | 6 +++++-
ac3a84
 src/network/networkd-route.c   | 6 +++++-
ac3a84
 2 files changed, 10 insertions(+), 2 deletions(-)
ac3a84
ac3a84
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
ac3a84
index 259cd312c9..4f8f95cba6 100644
ac3a84
--- a/src/network/networkd-address.c
ac3a84
+++ b/src/network/networkd-address.c
ac3a84
@@ -1189,9 +1189,13 @@ int link_request_address(
ac3a84
 
ac3a84
         (void) address_get(link, address, &existing);
ac3a84
 
ac3a84
-        if (address->lifetime_valid_usec == 0)
ac3a84
+        if (address->lifetime_valid_usec == 0) {
ac3a84
+                if (consume_object)
ac3a84
+                        address_free(address);
ac3a84
+
ac3a84
                 /* The requested address is outdated. Let's remove it. */
ac3a84
                 return address_remove_and_drop(existing);
ac3a84
+        }
ac3a84
 
ac3a84
         if (!existing) {
ac3a84
                 _cleanup_(address_freep) Address *tmp = NULL;
ac3a84
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
ac3a84
index d1f3bab092..5214a8ad2c 100644
ac3a84
--- a/src/network/networkd-route.c
ac3a84
+++ b/src/network/networkd-route.c
ac3a84
@@ -1437,9 +1437,13 @@ int link_request_route(
ac3a84
 
ac3a84
         (void) route_get(link->manager, link, route, &existing);
ac3a84
 
ac3a84
-        if (route->lifetime_usec == 0)
ac3a84
+        if (route->lifetime_usec == 0) {
ac3a84
+                if (consume_object)
ac3a84
+                        route_free(route);
ac3a84
+
ac3a84
                 /* The requested route is outdated. Let's remove it. */
ac3a84
                 return route_remove_and_drop(existing);
ac3a84
+        }
ac3a84
 
ac3a84
         if (!existing) {
ac3a84
                 _cleanup_(route_freep) Route *tmp = NULL;