improve error checking for gw_get_repo_heads
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 0707fdc..60c969d 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -173,7 +173,7 @@ static const struct got_error *gw_get_diff(char **, struct gw_trans *,
struct gw_header *);
static const struct got_error *gw_get_repo_tags(char **, struct gw_trans *,
struct gw_header *, int, int);
-static char *gw_get_repo_heads(struct gw_trans *);
+static const struct got_error *gw_get_repo_heads(char **, struct gw_trans *);
static const struct got_error *gw_get_clone_url(char **, struct gw_trans *, char *);
static char *gw_get_got_link(struct gw_trans *);
static char *gw_get_site_link(struct gw_trans *);
@@ -1150,7 +1150,9 @@ gw_summary(struct gw_trans *gw_trans)
}
/* heads */
- heads = gw_get_repo_heads(gw_trans);
+ error = gw_get_repo_heads(&heads, gw_trans);
+ if (error)
+ goto done;
if (heads != NULL && strcmp(heads, "") != 0) {
kerr = khtml_attr(gw_trans->gw_html_req, KELEM_DIV,
KATTR_ID, "summary_heads_title_wrapper", KATTR__MAX);
@@ -3166,17 +3168,19 @@ done:
return error;
}
-static char *
-gw_get_repo_heads(struct gw_trans *gw_trans)
+static const struct got_error *
+gw_get_repo_heads(char **head_html, struct gw_trans *gw_trans)
{
const struct got_error *error = NULL;
struct got_repository *repo = NULL;
struct got_reflist_head refs;
struct got_reflist_entry *re;
- char *heads, *head_row = NULL, *head_navs_disp = NULL, *age = NULL;
+ char *head_row = NULL, *head_navs_disp = NULL, *age = NULL;
struct buf *diffbuf = NULL;
size_t newsize;
+ *head_html = NULL;
+
SIMPLEQ_INIT(&refs);
error = buf_alloc(&diffbuf, 0);
@@ -3236,17 +3240,16 @@ gw_get_repo_heads(struct gw_trans *gw_trans)
if (buf_len(diffbuf) > 0) {
error = buf_putc(diffbuf, '\0');
- heads = strdup(buf_get(diffbuf));
+ *head_html = strdup(buf_get(diffbuf));
+ if (*head_html == NULL)
+ error = got_error_from_errno("strdup");
}
done:
buf_free(diffbuf);
got_ref_list_free(&refs);
if (repo)
got_repo_close(repo);
- if (error)
- return NULL;
- else
- return heads;
+ return error;
}
static char *