commit a81394a7f726210bfe52c33778710d09d1273b5e from: Stefan Sperling date: Thu Feb 13 20:42:44 2020 UTC eliminate unnecessary strdup() via an intermediate variable in gw_get_commit() commit - 53e81e487b1258083f28cdc605a4685043a6185d commit + a81394a7f726210bfe52c33778710d09d1273b5e blob - a809bdcaa28d5b074ac172ff710942051f19c582 blob + 3cd7a419d6fa87f132d95975582a660af2bf8c91 --- gotweb/gotweb.c +++ gotweb/gotweb.c @@ -3051,7 +3051,7 @@ gw_get_commit(struct gw_trans *gw_trans, struct gw_hea 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_hea 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;