Commit Diff


commit - f85c939fb7758c7cad91e0705b4d932d52597867
commit + 3bb657abe5b3a3d888deadbdc094637dd505dce0
blob - b498aeb95d0c3982fd3b2dca375879bbfff492d4
blob + 7e31416650c0a4ab9b782f2537ab2cf69b10993a
--- gotwebd/gotwebd.c
+++ gotwebd/gotwebd.c
@@ -94,12 +94,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) {
@@ -107,15 +107,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