From c9e9b13a7a3bb09bc4e6a124f12ce6bf0d76faac Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 10 May 2018 01:04:53 +0200 Subject: [PATCH] shared/sleep-config: fix memleak of strv, add test CID #1390921, #1390951. --- src/shared/sleep-config.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 159003886..68dee9ef3 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -4,19 +4,6 @@ Copyright 2013 Zbigniew Jędrzejewski-Szmek Copyright 2018 Dell Inc. - - elogind is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1 of the License, or - (at your option) any later version. - - elogind is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with elogind; If not, see . ***/ //#include @@ -48,7 +35,7 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states, usec_t **suspend_mode = NULL, **suspend_state = NULL, **hibernate_mode = NULL, **hibernate_state = NULL, **hybrid_mode = NULL, **hybrid_state = NULL; - char **modes, **states; + _cleanup_strv_free_ char **modes, **states; /* always initialized below */ usec_t delay = 180 * USEC_PER_MINUTE; const ConfigTableItem items[] = { @@ -104,16 +91,13 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states, usec_t assert_not_reached("what verb"); if ((!modes && STR_IN_SET(verb, "hibernate", "hybrid-sleep")) || - (!states && !streq(verb, "suspend-then-hibernate"))) { - strv_free(modes); - strv_free(states); + (!states && !streq(verb, "suspend-then-hibernate"))) return log_oom(); - } if (_modes) - *_modes = modes; + *_modes = TAKE_PTR(modes); if (_states) - *_states = states; + *_states = TAKE_PTR(states); if (_delay) *_delay = delay; -- 2.30.2