Blame SOURCES/libcgroup-0.41-api.c-tasks-file-warning.patch

340c38
diff --git a/src/api.c b/src/api.c
340c38
index a98e829..d19abdd 100644
340c38
--- a/src/api.c
340c38
+++ b/src/api.c
340c38
@@ -1190,12 +1190,15 @@ static int __cgroup_attach_task_pid(char *path, pid_t tid)
340c38
 	if (!tasks) {
340c38
 		switch (errno) {
340c38
 		case EPERM:
340c38
-			return ECGROUPNOTOWNER;
340c38
+			ret = ECGROUPNOTOWNER;
340c38
+			break;
340c38
 		case ENOENT:
340c38
-			return ECGROUPNOTEXIST;
340c38
+			ret = ECGROUPNOTEXIST;
340c38
+			break;
340c38
 		default:
340c38
-			return ECGROUPNOTALLOWED;
340c38
+			ret = ECGROUPNOTALLOWED;
340c38
 		}
340c38
+		goto err;
340c38
 	}
340c38
 	ret = fprintf(tasks, "%d", tid);
340c38
 	if (ret < 0) {
340c38
@@ -1214,7 +1217,8 @@ static int __cgroup_attach_task_pid(char *path, pid_t tid)
340c38
 err:
340c38
 	cgroup_warn("Warning: cannot write tid %d to %s:%s\n",
340c38
 			tid, path, strerror(errno));
340c38
-	fclose(tasks);
340c38
+	if (tasks)
340c38
+		fclose(tasks);
340c38
 	return ret;
340c38
 }
340c38