eliminate unnecessary strdup() via an intermediate variable in gw_get_commit()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index a809bdc..3cd7a41 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -3051,7 +3051,7 @@ gw_get_commit(struct gw_trans *gw_trans, struct gw_header *header)
struct got_reflist_entry *re;
struct got_object_id *id2 = NULL;
struct got_object_qid *parent_id;
- char *refs_str = NULL, *commit_msg = NULL, *commit_msg0;
+ char *commit_msg = NULL, *commit_msg0;
/*print commit*/
SIMPLEQ_FOREACH(re, &header->refs, entry) {
@@ -3091,23 +3091,17 @@ gw_get_commit(struct gw_trans *gw_trans, struct gw_header *header)
got_object_tag_close(tag);
if (cmp != 0)
continue;
- s = refs_str;
- if (asprintf(&refs_str, "%s%s%s", s ? s : "",
+ s = header->refs_str;
+ if (asprintf(&header->refs_str, "%s%s%s", s ? s : "",
s ? ", " : "", name) == -1) {
error = got_error_from_errno("asprintf");
free(s);
+ header->refs_str = NULL;
return error;
}
free(s);
- header->refs_str = strdup(refs_str);
- if (header->refs_str == NULL) {
- error = got_error_from_errno("strdup");
- return error;
- }
}
- free(refs_str);
-
error = got_object_id_str(&header->commit_id, header->id);
if (error)
return error;