Commit Diff


commit - 9472af9550ec85323ab6c004d71f8a671a6b014d
commit + f292b27176775cc4061f3da0be7fe0efcaf0325c
blob - 07e729502bd265d19becc465a899c24ecb04323a
blob + 572a730d092394c09f1ea83b262cf72884cc2dac
--- tog/tog.c
+++ tog/tog.c
@@ -2500,36 +2500,30 @@ draw_commit(struct tog_view *view, struct got_commit_o
 	/* Prepend reference labels to log message if possible .*/
 	refs = got_reflist_object_id_map_lookup(tog_refs_idmap, id);
 	if (refs) {
-		char *refs_str, *p, *newlogmsg;
+		char *refs_str, *newlogmsg;
 		wchar_t *ws;
 
 		err = build_refs_str(&refs_str, refs, id, s->repo);
 		if (err)
 			goto done;
-
-		if (asprintf(&p, "[%s]", refs_str) == -1) {
-			err = got_error_from_errno("asprintf");
-			free(refs_str);
-			goto done;
-		}
-		free(refs_str);
-		refs_str = NULL;
 	
 		/*
 		 * The length of this wide-char sub-string will be
 		 * needed later for colorization.
 		 */
-		err = mbs2ws(&ws, &wrefstr_len, p);
+		err = mbs2ws(&ws, &wrefstr_len, refs_str);
 		if (err)
 			goto done;
 		free(ws);
 
-		if (asprintf(&newlogmsg, "%s %s", p, logmsg) == -1) {
+		wrefstr_len += 2; /* account for '[' and ']' */
+
+		if (asprintf(&newlogmsg, "[%s] %s", refs_str, logmsg) == -1) {
 			err = got_error_from_errno("asprintf");
-			free(p);
+			free(refs_str);
 			goto done;
 		}
-		free(p);
+		free(refs_str);
 
 		free(logmsg0);
 		logmsg0 = newlogmsg;