"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
plug some leaks in `got import`
To:
gameoftrees@openbsd.org
Date:
Wed, 11 Dec 2024 22:59:51 +1100

Download raw body.

Thread
Spotted by chance when investigating moving get_author() to the library:
we leak some objects with early returns in a couple error cases instead
of going to done to cleanup; and we also forgot to free the path_dir
char pointer, and ignores pathlist.


commit 0335fad923fe3a80a362a6698ec919e6cbcd362f (main)
from: Mark Jamsek <mark@jamsek.dev>
date: Wed Dec 11 11:44:20 2024 UTC

got: plug a couple leaks in `got import`

Make sure we always cleanup in the error case; free the ignore pathlist;
and free the path_dir char pointer.

M  got/got.c  |  11+  5-

1 file changed, 11 insertions(+), 5 deletions(-)

commit - 45b12d17fa516fdd411ecdea1d13fa79340a223a
commit + 0335fad923fe3a80a362a6698ec919e6cbcd362f
blob - ed5defc312e6a540e5c6a78407f1fa1d9dce3812
blob + 5493a5339d1cfcb92aac6c450ddb5cfa5578f40c
--- got/got.c
+++ got/got.c
@@ -892,8 +892,10 @@ cmd_import(int argc, char *argv[])
 
 	if (repo_path == NULL) {
 		repo_path = getcwd(NULL, 0);
-		if (repo_path == NULL)
-			return got_error_from_errno("getcwd");
+		if (repo_path == NULL) {
+			error = got_error_from_errno("getcwd");
+			goto done;
+		}
 	}
 	got_path_strip_trailing_slashes(repo_path);
 	error = get_gitconfig_path(&gitconfig_path);
@@ -931,15 +933,17 @@ cmd_import(int argc, char *argv[])
 
 	error = get_author(&author, repo, NULL);
 	if (error)
-		return error;
+		goto done;
 
 	/*
 	 * Don't let the user create a branch name with a leading '-'.
 	 * While technically a valid reference name, this case is usually
 	 * an unintended typo.
 	 */
-	if (branch_name && branch_name[0] == '-')
-		return got_error_path(branch_name, GOT_ERR_REF_NAME_MINUS);
+	if (branch_name && branch_name[0] == '-') {
+		error = got_error_path(branch_name, GOT_ERR_REF_NAME_MINUS);
+		goto done;
+	}
 
 	error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
 	if (error && error->code != GOT_ERR_NOT_REF)
@@ -1051,8 +1055,10 @@ done:
 		    getprogname(), logmsg_path);
 	} else if (logmsg_path && unlink(logmsg_path) == -1 && error == NULL)
 		error = got_error_from_errno2("unlink", logmsg_path);
+	got_pathlist_free(&ignores, GOT_PATHLIST_FREE_NONE);
 	free(logmsg);
 	free(logmsg_path);
+	free(path_dir);
 	free(repo_path);
 	free(editor);
 	free(new_commit_id);


-- 
Mark Jamsek <https://bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68