Commit 621015ac3ab52e480c58727e69a7a7ee4f945699

Stefan Sperling 2018-07-23T11:58:54

use strsep() correctly in got's print_commit()

diff --git a/got/got.c b/got/got.c
index 21b696a..7c0bf3a 100644
--- a/got/got.c
+++ b/got/got.c
@@ -311,7 +311,7 @@ print_commit(struct got_commit_object *commit, struct got_object_id *id,
     struct got_repository *repo, int show_patch)
 {
 	const struct got_error *err = NULL;
-	char *id_str, *datestr, *logmsg, *line;
+	char *id_str, *datestr, *logmsg0, *logmsg, *line;
 	char datebuf[26];
 	time_t author_time, committer_time;
 
@@ -349,16 +349,17 @@ print_commit(struct got_commit_object *commit, struct got_object_id *id,
 		}
 	}
 
-	logmsg = strdup(commit->logmsg);
-	if (logmsg == NULL)
+	logmsg0 = strdup(commit->logmsg);
+	if (logmsg0 == NULL)
 		return got_error_from_errno();
 
+	logmsg = logmsg0;
 	do {
 		line = strsep(&logmsg, "\n");
 		if (line)
 			printf(" %s\n", line);
 	} while (line);
-	free(logmsg);
+	free(logmsg0);
 
 	if (show_patch) {
 		err = print_patch(commit, id, repo);