commit - 49c7094fd1f4489f4e5880e2d649aa27ea65e2fd
commit + 5e1c9f2326a6e3d33c6e0ff547f59e1ef91d62da
blob - 569469beed32d05c207dbf9cd3067ed433793128
blob + 0e002c4fcedc1d9aee2f3af1c9556f2b32c4890f
--- lib/path.c
+++ lib/path.c
make_parent_dirs(const char *abspath)
{
const struct got_error *err = NULL;
+ char *p, *parent;
- char *parent = dirname(abspath);
+ p = dirname(abspath);
+ if (p == NULL)
+ return got_error_from_errno();
+ parent = strdup(p);
if (parent == NULL)
- return NULL;
+ return got_error_from_errno();
if (mkdir(parent, GOT_DEFAULT_DIR_MODE) == -1) {
if (errno == ENOENT) {
err = make_parent_dirs(parent);
if (err)
- return err;
- if (mkdir(parent, GOT_DEFAULT_DIR_MODE) == -1)
- return got_error_from_errno();
+ goto done;
+ if (mkdir(parent, GOT_DEFAULT_DIR_MODE) == -1) {
+ err = got_error_from_errno();
+ goto done;
+ }
} else
err = got_error_from_errno();
}
-
+done:
+ free(parent);
return err;
}
blob - 8071dfb58a04a1feb6a27a782e1b5d9c5c2dcb88
blob + 66e45886c2e46b2ad626492278f97eb1568393e7
--- lib/reference.c
+++ lib/reference.c
err = got_opentemp_named(&tmppath, &f, path);
if (err) {
- char *parent;
+ char *p, *parent;
if (!(err->code == GOT_ERR_ERRNO && errno == ENOENT))
goto done;
- parent = dirname(path);
+ p = dirname(path);
+ if (p == NULL) {
+ err = got_error_from_errno();
+ goto done;
+ }
+ parent = strdup(p);
if (parent == NULL) {
err = got_error_from_errno();
goto done;
}
err = got_path_mkdir(parent);
+ free(parent);
if (err)
goto done;
err = got_opentemp_named(&tmppath, &f, path);