Skip to content
Browse files

Fix initialization & freeing of inexistent repos

Signed-off-by: Vicent Marti <tanoku@gmail.com>
  • Loading branch information...
1 parent e0d9e12 commit 1f080e2da4833004fd178f622271879336085e22 @vmg vmg committed
Showing with 33 additions and 8 deletions.
  1. +7 −2 src/fileops.c
  2. +2 −1 src/odb.c
  3. +12 −5 src/repository.c
  4. +12 −0 src/revwalk.c
View
9 src/fileops.c
@@ -74,8 +74,13 @@ int gitfo_isdir(const char *path)
stat_error = gitfo_stat(path, &st);
}
- return (stat_error == 0 && S_ISDIR(st.st_mode)) ?
- GIT_SUCCESS : GIT_ENOTFOUND;
+ if (stat_error < GIT_SUCCESS)
+ return GIT_ENOTFOUND;
+
+ if (!S_ISDIR(st.st_mode))
+ return GIT_ENOTFOUND;
+
+ return GIT_SUCCESS;
}
int gitfo_exists(const char *path)
View
3 src/odb.c
@@ -210,7 +210,8 @@ void git_odb_close(git_odb *db)
{
unsigned int i;
- assert(db);
+ if (db == NULL)
+ return;
for (i = 0; i < db->backends.length; ++i) {
git_odb_backend *b = git_vector_get(&db->backends, i);
View
17 src/repository.c
@@ -103,7 +103,6 @@ static int assign_repository_folders(git_repository *repo,
if (git_dir == NULL || gitfo_isdir(git_dir) < GIT_SUCCESS)
return GIT_ENOTFOUND;
-
/* store GIT_DIR */
path_len = strlen(git_dir);
strcpy(path_aux, git_dir);
@@ -279,6 +278,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
if (error < GIT_SUCCESS)
goto cleanup;
+
error = git_odb_open(&repo->db, repo->path_odb);
if (error < GIT_SUCCESS)
goto cleanup;
@@ -296,7 +296,8 @@ void git_repository_free(git_repository *repo)
git_hashtable_iterator it;
git_object *object;
- assert(repo);
+ if (repo == NULL)
+ return;
free(repo->path_workdir);
free(repo->path_index);
@@ -310,8 +311,13 @@ void git_repository_free(git_repository *repo)
git_object_free(object);
git_hashtable_free(repo->objects);
- git_odb_close(repo->db);
- git_index_free(repo->index);
+
+ if (repo->db != NULL)
+ git_odb_close(repo->db);
+
+ if (repo->index != NULL)
+ git_index_free(repo->index);
+
free(repo);
}
@@ -511,7 +517,8 @@ int git_object_write(git_object *object)
void git_object_free(git_object *object)
{
- assert(object);
+ if (object == NULL)
+ return;
git_object__source_close(object);
git_hashtable_remove(object->repo->objects, &object->id);
View
12 src/revwalk.c
@@ -77,6 +77,9 @@ int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo)
void git_revwalk_free(git_revwalk *walk)
{
+ if (walk == NULL)
+ return;
+
git_revwalk_reset(walk);
git_hashtable_free(walk->commits);
free(walk);
@@ -90,6 +93,8 @@ git_repository *git_revwalk_repository(git_revwalk *walk)
int git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
{
+ assert(walk);
+
if (walk->walking)
return GIT_EBUSY;
@@ -165,6 +170,7 @@ static git_revwalk_commit *insert_commit(git_revwalk *walk, git_commit *commit_o
int git_revwalk_push(git_revwalk *walk, git_commit *commit)
{
+ assert(walk && commit);
return insert_commit(walk, commit) ? GIT_SUCCESS : GIT_ENOMEM;
}
@@ -186,6 +192,8 @@ static void mark_uninteresting(git_revwalk_commit *commit)
int git_revwalk_hide(git_revwalk *walk, git_commit *commit)
{
git_revwalk_commit *hide;
+
+ assert(walk && commit);
hide = insert_commit(walk, commit);
if (hide == NULL)
@@ -216,6 +224,8 @@ git_commit *git_revwalk_next(git_revwalk *walk)
{
git_revwalk_commit *next;
+ assert(walk);
+
if (!walk->walking)
prepare_walk(walk);
@@ -234,6 +244,8 @@ void git_revwalk_reset(git_revwalk *walk)
git_hashtable_iterator it;
git_revwalk_commit *commit;
+ assert(walk);
+
git_hashtable_iterator_init(walk->commits, &it);
while ((commit = (git_revwalk_commit *)

0 comments on commit 1f080e2

Please sign in to comment.
Something went wrong with that request. Please try again.