consistent error return from gw_init_gw_dir()
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 a8bbb9d..8e77989 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -153,7 +153,7 @@ static const struct kvalid gw_keys[KEY__ZMAX] = {
{ kvalid_stringne, "path" },
};
-static struct gw_dir *gw_init_gw_dir(char *);
+static const struct got_error *gw_init_gw_dir(struct gw_dir **, char *);
static struct gw_header *gw_init_header(void);
static void gw_free_headers(struct gw_header *);
@@ -1602,8 +1602,9 @@ gw_load_got_paths(struct gw_trans *gw_trans)
strcmp(sd_dent[d_i]->d_name, "..") == 0)
continue;
- if ((gw_dir = gw_init_gw_dir(sd_dent[d_i]->d_name)) == NULL)
- return got_error_from_errno("gw_dir malloc");
+ error = gw_init_gw_dir(&gw_dir, sd_dent[d_i]->d_name);
+ if (error)
+ return error;
error = gw_load_got_path(gw_trans, gw_dir);
if (error && error->code == GOT_ERR_NOT_GIT_REPO) {
@@ -1691,9 +1692,9 @@ gw_parse_querystring(struct gw_trans *gw_trans)
error = got_error_from_errno("invalid action");
return error;
}
- if ((gw_trans->gw_dir =
- gw_init_gw_dir(gw_trans->repo_name)) == NULL)
- return got_error_from_errno("gw_dir malloc");
+ error = gw_init_gw_dir(&gw_trans->gw_dir, gw_trans->repo_name);
+ if (error)
+ return error;
error = gw_load_got_path(gw_trans, gw_trans->gw_dir);
if (error)
@@ -1707,18 +1708,23 @@ gw_parse_querystring(struct gw_trans *gw_trans)
return error;
}
-static struct gw_dir *
-gw_init_gw_dir(char *dir)
+static const struct got_error *
+gw_init_gw_dir(struct gw_dir **gw_dir, char *dir)
{
- struct gw_dir *gw_dir;
+ const struct got_error *error;
- if ((gw_dir = malloc(sizeof(*gw_dir))) == NULL)
- return NULL;
+ *gw_dir = malloc(sizeof(**gw_dir));
+ if (*gw_dir == NULL)
+ return got_error_from_errno("malloc");
- if (asprintf(&gw_dir->name, "%s", dir) == -1)
+ if (asprintf(&(*gw_dir)->name, "%s", dir) == -1) {
+ error = got_error_from_errno("asprintf");
+ free(*gw_dir);
+ *gw_dir = NULL;
return NULL;
+ }
- return gw_dir;
+ return NULL;
}
static const struct got_error *