daandemeyer / rpms / systemd

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