anitazha / rpms / systemd

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