move gw_conf malloc to parse.y and cleanup another one-line set/check fix rash pointer change in last edit
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
diff --git a/gotweb/gotweb.c b/gotweb/gotweb.c
index 0af46f6..f52838f 100644
--- a/gotweb/gotweb.c
+++ b/gotweb/gotweb.c
@@ -4656,13 +4656,6 @@ main(int argc, char *argv[])
goto done;
}
- if ((gw_trans->gw_conf =
- malloc(sizeof(struct gotweb_config))) == NULL) {
- gw_malloc = 0;
- error = got_error_from_errno("malloc");
- goto done;
- }
-
TAILQ_INIT(&gw_trans->gw_dirs);
TAILQ_INIT(&gw_trans->gw_headers);
@@ -4702,6 +4695,7 @@ done:
free(gw_trans->gw_conf->got_site_link);
free(gw_trans->gw_conf->got_logo);
free(gw_trans->gw_conf->got_logo_url);
+ free(gw_trans->gw_conf);
free(gw_trans->commit_id);
free(gw_trans->next_id);
free(gw_trans->next_prev_id);
diff --git a/gotweb/parse.y b/gotweb/parse.y
index f9275d1..e137202 100644
--- a/gotweb/parse.y
+++ b/gotweb/parse.y
@@ -84,7 +84,7 @@ int symset(const char *, const char *, int);
char *symget(const char *);
const struct got_error* gerror = NULL;
-struct gotweb_config gw_conf;
+struct gotweb_config *gw_conf;
typedef struct {
union {
@@ -129,8 +129,8 @@ boolean : STRING {
| ON { $$ = 1; }
;
main : GOT_REPOS_PATH STRING {
- gw_conf.got_repos_path = strdup($2);
- if (gw_conf.got_repos_path== NULL) {
+ gw_conf->got_repos_path = strdup($2);
+ if (gw_conf->got_repos_path== NULL) {
free($2);
yyerror("strdup");
YYERROR;
@@ -138,70 +138,70 @@ main : GOT_REPOS_PATH STRING {
}
| GOT_MAX_REPOS NUMBER {
if ($2 > 0)
- gw_conf.got_max_repos = $2;
+ gw_conf->got_max_repos = $2;
}
| GOT_SITE_NAME STRING {
- gw_conf.got_site_name = strdup($2);
- if (gw_conf.got_site_name == NULL) {
+ gw_conf->got_site_name = strdup($2);
+ if (gw_conf->got_site_name == NULL) {
free($2);
yyerror("strdup");
YYERROR;
}
}
| GOT_SITE_OWNER STRING {
- gw_conf.got_site_owner = strdup($2);
- if (gw_conf.got_site_owner == NULL) {
+ gw_conf->got_site_owner = strdup($2);
+ if (gw_conf->got_site_owner == NULL) {
free($2);
yyerror("strdup");
YYERROR;
}
}
| GOT_SITE_LINK STRING {
- gw_conf.got_site_link = strdup($2);
- if (gw_conf.got_site_link == NULL) {
+ gw_conf->got_site_link = strdup($2);
+ if (gw_conf->got_site_link == NULL) {
free($2);
yyerror("strdup");
YYERROR;
}
}
| GOT_LOGO STRING {
- gw_conf.got_logo = strdup($2);
- if (gw_conf.got_logo== NULL) {
+ gw_conf->got_logo = strdup($2);
+ if (gw_conf->got_logo== NULL) {
free($2);
yyerror("strdup");
YYERROR;
}
}
| GOT_LOGO_URL STRING {
- gw_conf.got_logo_url = strdup($2);
- if (gw_conf.got_logo_url== NULL) {
+ gw_conf->got_logo_url = strdup($2);
+ if (gw_conf->got_logo_url== NULL) {
free($2);
yyerror("strdup");
YYERROR;
}
}
| GOT_SHOW_SITE_OWNER boolean {
- gw_conf.got_show_site_owner = $2;
+ gw_conf->got_show_site_owner = $2;
}
| GOT_SHOW_REPO_OWNER boolean {
- gw_conf.got_show_repo_owner = $2;
+ gw_conf->got_show_repo_owner = $2;
}
| GOT_SHOW_REPO_AGE boolean {
- gw_conf.got_show_repo_age = $2;
+ gw_conf->got_show_repo_age = $2;
}
| GOT_SHOW_REPO_DESCRIPTION boolean {
- gw_conf.got_show_repo_description = $2;
+ gw_conf->got_show_repo_description = $2;
}
| GOT_SHOW_REPO_CLONEURL boolean {
- gw_conf.got_show_repo_cloneurl = $2;
+ gw_conf->got_show_repo_cloneurl = $2;
}
| GOT_MAX_REPOS_DISPLAY NUMBER {
if ($2 > 0)
- gw_conf.got_max_repos_display = $2;
+ gw_conf->got_max_repos_display = $2;
}
| GOT_MAX_COMMITS_DISPLAY NUMBER {
if ($2 > 0)
- gw_conf.got_max_commits_display = $2;
+ gw_conf->got_max_commits_display = $2;
}
;
%%
@@ -581,44 +581,49 @@ popfile(void)
const struct got_error*
parse_gotweb_config(struct gotweb_config **gconf, const char *filename)
{
- gw_conf.got_repos_path = strdup(D_GOTPATH);
- if (gw_conf.got_repos_path == NULL) {
+ gw_conf = malloc(sizeof(struct gotweb_config));
+ if (gw_conf == NULL) {
+ gerror = got_error_from_errno("malloc");
+ goto done;
+ }
+ gw_conf->got_repos_path = strdup(D_GOTPATH);
+ if (gw_conf->got_repos_path == NULL) {
gerror = got_error_from_errno("strdup");
goto done;
}
- gw_conf.got_site_name = strdup(D_SITENAME);
- if (gw_conf.got_site_name == NULL) {
+ gw_conf->got_site_name = strdup(D_SITENAME);
+ if (gw_conf->got_site_name == NULL) {
gerror = got_error_from_errno("strdup");
goto done;
}
- gw_conf.got_site_owner = strdup(D_SITEOWNER);
- if (gw_conf.got_site_owner == NULL) {
+ gw_conf->got_site_owner = strdup(D_SITEOWNER);
+ if (gw_conf->got_site_owner == NULL) {
gerror = got_error_from_errno("strdup");
goto done;
}
- gw_conf.got_site_link = strdup(D_SITELINK);
- if (gw_conf.got_site_link == NULL) {
+ gw_conf->got_site_link = strdup(D_SITELINK);
+ if (gw_conf->got_site_link == NULL) {
gerror = got_error_from_errno("strdup");
goto done;
}
- gw_conf.got_logo = strdup(D_GOTLOGO);
- if (gw_conf.got_logo == NULL) {
+ gw_conf->got_logo = strdup(D_GOTLOGO);
+ if (gw_conf->got_logo == NULL) {
gerror = got_error_from_errno("strdup");
goto done;
}
- gw_conf.got_logo_url = strdup(D_GOTURL);
- if (gw_conf.got_logo_url == NULL) {
+ gw_conf->got_logo_url = strdup(D_GOTURL);
+ if (gw_conf->got_logo_url == NULL) {
gerror = got_error_from_errno("strdup");
goto done;
}
- gw_conf.got_show_site_owner = D_SHOWSOWNER;
- gw_conf.got_show_repo_owner = D_SHOWROWNER;
- gw_conf.got_show_repo_age = D_SHOWAGE;
- gw_conf.got_show_repo_description = D_SHOWDESC;
- gw_conf.got_show_repo_cloneurl = D_SHOWURL;
- gw_conf.got_max_repos = D_MAXREPO;
- gw_conf.got_max_repos_display = D_MAXREPODISP;
- gw_conf.got_max_commits_display = D_MAXCOMMITDISP;
+ gw_conf->got_show_site_owner = D_SHOWSOWNER;
+ gw_conf->got_show_repo_owner = D_SHOWROWNER;
+ gw_conf->got_show_repo_age = D_SHOWAGE;
+ gw_conf->got_show_repo_description = D_SHOWDESC;
+ gw_conf->got_show_repo_cloneurl = D_SHOWURL;
+ gw_conf->got_max_repos = D_MAXREPO;
+ gw_conf->got_max_repos_display = D_MAXREPODISP;
+ gw_conf->got_max_commits_display = D_MAXCOMMITDISP;
/*
* We don't require that the gotweb config file exists
@@ -635,7 +640,7 @@ parse_gotweb_config(struct gotweb_config **gconf, const char *filename)
yyparse();
popfile();
done:
- *gconf = &gw_conf;
+ *gconf = gw_conf;
return gerror;
}