|
|
65878a |
From c26444ca9751a1f7cec28f8140b9674cec2ee3ce Mon Sep 17 00:00:00 2001
|
|
|
65878a |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
65878a |
Date: Sun, 15 Dec 2013 16:25:04 -0500
|
|
|
65878a |
Subject: [PATCH] Fix a few resource leaks in error paths
|
|
|
65878a |
|
|
|
65878a |
https://bugzilla.redhat.com/show_bug.cgi?id=1043304
|
|
|
65878a |
|
|
|
65878a |
Conflicts:
|
|
|
65878a |
src/libsystemd-bus/bus-objects.c
|
|
|
65878a |
src/udev/net/link-config.c
|
|
|
65878a |
---
|
|
|
65878a |
src/sleep/sleep.c | 15 +++++++--------
|
|
|
65878a |
1 file changed, 7 insertions(+), 8 deletions(-)
|
|
|
65878a |
|
|
|
65878a |
diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c
|
|
|
65878a |
index a56ab89..f96987f 100644
|
|
|
65878a |
--- a/src/sleep/sleep.c
|
|
|
65878a |
+++ b/src/sleep/sleep.c
|
|
|
65878a |
@@ -57,15 +57,14 @@ static int write_mode(char **modes) {
|
|
|
65878a |
return r;
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
-static int write_state(FILE *f0, char **states) {
|
|
|
65878a |
- FILE _cleanup_fclose_ *f = f0;
|
|
|
65878a |
+static int write_state(FILE **f, char **states) {
|
|
|
65878a |
char **state;
|
|
|
65878a |
int r = 0;
|
|
|
65878a |
|
|
|
65878a |
STRV_FOREACH(state, states) {
|
|
|
65878a |
int k;
|
|
|
65878a |
|
|
|
65878a |
- k = write_string_to_file(f, *state);
|
|
|
65878a |
+ k = write_string_to_file(*f, *state);
|
|
|
65878a |
if (k == 0)
|
|
|
65878a |
return 0;
|
|
|
65878a |
log_debug("Failed to write '%s' to /sys/power/state: %s",
|
|
|
65878a |
@@ -73,9 +72,9 @@ static int write_state(FILE *f0, char **states) {
|
|
|
65878a |
if (r == 0)
|
|
|
65878a |
r = k;
|
|
|
65878a |
|
|
|
65878a |
- fclose(f);
|
|
|
65878a |
- f = fopen("/sys/power/state", "we");
|
|
|
65878a |
- if (!f) {
|
|
|
65878a |
+ fclose(*f);
|
|
|
65878a |
+ *f = fopen("/sys/power/state", "we");
|
|
|
65878a |
+ if (!*f) {
|
|
|
65878a |
log_error("Failed to open /sys/power/state: %m");
|
|
|
65878a |
return -errno;
|
|
|
65878a |
}
|
|
|
65878a |
@@ -87,7 +86,7 @@ static int write_state(FILE *f0, char **states) {
|
|
|
65878a |
static int execute(char **modes, char **states) {
|
|
|
65878a |
char* arguments[4];
|
|
|
65878a |
int r;
|
|
|
65878a |
- FILE *f;
|
|
|
65878a |
+ _cleanup_fclose_ FILE *f = NULL;
|
|
|
65878a |
const char* note = strappenda("SLEEP=", arg_verb);
|
|
|
65878a |
|
|
|
65878a |
/* This file is opened first, so that if we hit an error,
|
|
|
65878a |
@@ -115,7 +114,7 @@ static int execute(char **modes, char **states) {
|
|
|
65878a |
note,
|
|
|
65878a |
NULL);
|
|
|
65878a |
|
|
|
65878a |
- r = write_state(f, states);
|
|
|
65878a |
+ r = write_state(&f, states);
|
|
|
65878a |
if (r < 0)
|
|
|
65878a |
return r;
|
|
|
65878a |
|