Commit Diff


commit - bc16f51e718bdcd7753429427c4920fa3419c32d
commit + 22af6a95d11edbe6ded4e23d85858238a9be64e2
blob - 349809a56e81c41f351d4a1a0b697969e031c83a
blob + cbcf820139e46dade5b52bbe6e2a5bbd3815b8ee
--- gotd/repo_write.c
+++ gotd/repo_write.c
@@ -2131,26 +2131,32 @@ render_notification(struct imsg *imsg, struct gotd_ims
 	const struct got_error *err = NULL;
 	struct gotd_imsg_notification_content ireq;
 	size_t datalen, len;
-	char *refname;
+	char *refname = NULL;
 	struct ibuf *wbuf;
-	int fd;
+	int fd = -1;
 
 	fd = imsg_get_fd(imsg);
 	if (fd == -1)
 		return got_error(GOT_ERR_PRIVSEP_NO_FD);
 
 	datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
-	if (datalen < sizeof(ireq))
-		return got_error(GOT_ERR_PRIVSEP_LEN);
+	if (datalen < sizeof(ireq)) {
+		err = got_error(GOT_ERR_PRIVSEP_LEN);
+		goto done;
+	}
 
 	memcpy(&ireq, imsg->data, sizeof(ireq));
 
-	if (datalen != sizeof(ireq) +  ireq.refname_len)
-		return got_error(GOT_ERR_PRIVSEP_LEN);
+	if (datalen != sizeof(ireq) +  ireq.refname_len) {
+		err = got_error(GOT_ERR_PRIVSEP_LEN);
+		goto done;
+	}
 
 	refname = strndup(imsg->data + sizeof(ireq), ireq.refname_len);
-	if (refname == NULL)
-		return got_error_from_errno("strndup");
+	if (refname == NULL) {
+		err =  got_error_from_errno("strndup");
+		goto done;
+	}
 
 	switch (ireq.action) {
 	case GOTD_NOTIF_ACTION_CREATED:
@@ -2192,7 +2198,7 @@ render_notification(struct imsg *imsg, struct gotd_ims
 	gotd_imsg_event_add(iev);
 done:
 	free(refname);
-	if (close(fd) == -1 && err == NULL)
+	if (fd != -1 && close(fd) == -1 && err == NULL)
 		err = got_error_from_errno("close");
 	return err;
 }