Commit Diff


commit - 26678adde25a1fb7fa3e4b78c82a888cc3b767e4
commit + b2ce80908e83c8a29aab68c76588a41813f13a74
blob - 4017a8fd50fbe849af03accbf3ef5e16ba4eb232
blob + 96fd5c7c164275779cca5fd8206b15f4af564a94
--- gotwebd/gotwebd.c
+++ gotwebd/gotwebd.c
@@ -95,12 +95,12 @@ main_compose_sockets(struct gotwebd *env, uint32_t typ
 	for (i = 0; i < env->nserver; ++i) {
 		d = -1;
 		if (fd != -1 && (d = dup(fd)) == -1)
-			return (-1);
+			goto err;
 
 		ret = imsg_compose_event(&env->iev_server[i], type, 0, -1,
 		    d, data, len);
 		if (ret == -1)
-			return (-1);
+			goto err;
 
 		/* prevent fd exhaustion */
 		if (d != -1) {
@@ -108,15 +108,19 @@ main_compose_sockets(struct gotwebd *env, uint32_t typ
 				ret = imsg_flush(&env->iev_server[i].ibuf);
 			} while (ret == -1 && errno == EAGAIN);
 			if (ret == -1)
-				return (-1);
+				goto err;
 			imsg_event_add(&env->iev_server[i]);
 		}
 	}
 
 	if (fd != -1)
 		close(fd);
-
 	return 0;
+
+err:
+	if (fd != -1)
+		close(fd);
+	return -1;
 }
 
 int