mirror of
https://github.com/systemd/systemd.git
synced 2024-11-06 16:59:03 +03:00
shared/sleep-config: fix memleak of strv, add test
CID #1390921, #1390951.
This commit is contained in:
parent
f5ce2e764f
commit
db983479af
@ -34,7 +34,7 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states, usec_t
|
|||||||
**suspend_mode = NULL, **suspend_state = NULL,
|
**suspend_mode = NULL, **suspend_state = NULL,
|
||||||
**hibernate_mode = NULL, **hibernate_state = NULL,
|
**hibernate_mode = NULL, **hibernate_state = NULL,
|
||||||
**hybrid_mode = NULL, **hybrid_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;
|
usec_t delay = 180 * USEC_PER_MINUTE;
|
||||||
|
|
||||||
const ConfigTableItem items[] = {
|
const ConfigTableItem items[] = {
|
||||||
@ -90,16 +90,13 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states, usec_t
|
|||||||
assert_not_reached("what verb");
|
assert_not_reached("what verb");
|
||||||
|
|
||||||
if ((!modes && STR_IN_SET(verb, "hibernate", "hybrid-sleep")) ||
|
if ((!modes && STR_IN_SET(verb, "hibernate", "hybrid-sleep")) ||
|
||||||
(!states && !streq(verb, "suspend-then-hibernate"))) {
|
(!states && !streq(verb, "suspend-then-hibernate")))
|
||||||
strv_free(modes);
|
|
||||||
strv_free(states);
|
|
||||||
return log_oom();
|
return log_oom();
|
||||||
}
|
|
||||||
|
|
||||||
if (_modes)
|
if (_modes)
|
||||||
*_modes = modes;
|
*_modes = TAKE_PTR(modes);
|
||||||
if (_states)
|
if (_states)
|
||||||
*_states = states;
|
*_states = TAKE_PTR(states);
|
||||||
if (_delay)
|
if (_delay)
|
||||||
*_delay = delay;
|
*_delay = delay;
|
||||||
|
|
||||||
|
@ -14,6 +14,13 @@
|
|||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
static void test_parse_sleep_config(void) {
|
||||||
|
const char *verb;
|
||||||
|
|
||||||
|
FOREACH_STRING(verb, "suspend", "hibernate", "hybrid-sleep", "suspend-then-hibernate")
|
||||||
|
assert_se(parse_sleep_config(verb, NULL, NULL, NULL) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
static int test_fiemap(const char *path) {
|
static int test_fiemap(const char *path) {
|
||||||
_cleanup_free_ struct fiemap *fiemap = NULL;
|
_cleanup_free_ struct fiemap *fiemap = NULL;
|
||||||
_cleanup_close_ int fd = -1;
|
_cleanup_close_ int fd = -1;
|
||||||
@ -84,6 +91,7 @@ int main(int argc, char* argv[]) {
|
|||||||
if (getuid() != 0)
|
if (getuid() != 0)
|
||||||
log_warning("This program is unlikely to work for unprivileged users");
|
log_warning("This program is unlikely to work for unprivileged users");
|
||||||
|
|
||||||
|
test_parse_sleep_config();
|
||||||
test_sleep();
|
test_sleep();
|
||||||
|
|
||||||
if (argc <= 1)
|
if (argc <= 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user