Download raw body.
gotwebd: simplify gotweb_load_got_path
landed here why looking for possible leaks. Still found none, but I
thought we can avoid an extra strdup and simplify the logic by
dropping `opened'. We either have opened a dir (and so dt is non
NULL) or we haven't.
ok?
diff /home/op/w/got
commit - 794662a4547b17c0243addf37d330d39e0eb5662
path + /home/op/w/got
blob - 72a93ffe88a0fd5d23ee1850893733ac1c37c39c
file + gotwebd/gotweb.c
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
@@ -1920,7 +1920,6 @@ gotweb_load_got_path(struct request *c, struct repo_di
struct transport *t = c->t;
DIR *dt;
char *dir_test;
- int opened = 0;
if (asprintf(&dir_test, "%s/%s/%s", srv->repos_path, repo_dir->name,
GOTWEB_GIT_DIR) == -1)
@@ -1930,52 +1929,36 @@ gotweb_load_got_path(struct request *c, struct repo_di
if (dt == NULL) {
free(dir_test);
} else {
- repo_dir->path = strdup(dir_test);
- if (repo_dir->path == NULL) {
- opened = 1;
- error = got_error_from_errno("strdup");
- goto err;
- }
- opened = 1;
+ repo_dir->path = dir_test;
+ dir_test = NULL;
goto done;
}
if (asprintf(&dir_test, "%s/%s/%s", srv->repos_path, repo_dir->name,
- GOTWEB_GOT_DIR) == -1) {
- dir_test = NULL;
- error = got_error_from_errno("asprintf");
- goto err;
- }
+ GOTWEB_GOT_DIR) == -1)
+ return got_error_from_errno("asprintf");
dt = opendir(dir_test);
if (dt == NULL)
free(dir_test);
else {
- opened = 1;
error = got_error(GOT_ERR_NOT_GIT_REPO);
goto err;
}
if (asprintf(&dir_test, "%s/%s", srv->repos_path,
- repo_dir->name) == -1) {
- error = got_error_from_errno("asprintf");
- dir_test = NULL;
- goto err;
- }
+ repo_dir->name) == -1)
+ return got_error_from_errno("asprintf");
- repo_dir->path = strdup(dir_test);
- if (repo_dir->path == NULL) {
- opened = 1;
- error = got_error_from_errno("strdup");
- goto err;
- }
-
dt = opendir(dir_test);
if (dt == NULL) {
error = got_error_path(repo_dir->name, GOT_ERR_NOT_GIT_REPO);
goto err;
- } else
- opened = 1;
+ } else {
+ repo_dir->path = dir_test;
+ dir_test = NULL;
+ }
+
done:
error = got_repo_open(&t->repo, repo_dir->path, NULL, sock->pack_fds);
if (error)
@@ -1994,9 +1977,8 @@ done:
error = gotweb_get_clone_url(&repo_dir->url, srv, repo_dir->path);
err:
free(dir_test);
- if (opened)
- if (dt != NULL && closedir(dt) == EOF && error == NULL)
- error = got_error_from_errno("closedir");
+ if (dt != NULL && closedir(dt) == EOF && error == NULL)
+ error = got_error_from_errno("closedir");
return error;
}
gotwebd: simplify gotweb_load_got_path