diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-03-05 01:17:59 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-03-05 02:05:26 +0200 |
| commit | f335b42c72fbc4842295f52b0654a8c54716847d (patch) | |
| tree | 04c074aad8e4f512131c26b71ebddda83a4bf06e /src/repository.h | |
| parent | e06dd9b6d650008c1b0731dea2de5dea1884fd28 (diff) | |
| download | libgit2-f335b42c72fbc4842295f52b0654a8c54716847d.tar.gz | |
Fix segmentation fault when freeing a repository
Disable garbage collection of cross-references to prevent
double-freeing. Internal reference management is now done
with a separate method.
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/repository.h')
| -rw-r--r-- | src/repository.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/repository.h b/src/repository.h index 4f4a4a863..5318ed45c 100644 --- a/src/repository.h +++ b/src/repository.h @@ -5,6 +5,7 @@ #include "git2/oid.h" #include "git2/odb.h" #include "git2/repository.h" +#include "git2/object.h" #include "hashtable.h" #include "index.h" @@ -44,7 +45,7 @@ struct git_repository { char *path_odb; char *path_workdir; - unsigned is_bare:1; + unsigned is_bare:1, gc_enabled:1; }; int git_object__source_open(git_object *object); @@ -60,12 +61,19 @@ int git__source_write(git_odb_source *source, const void *bytes, size_t len); int git__parse_oid(git_oid *oid, char **buffer_out, const char *buffer_end, const char *header); int git__write_oid(git_odb_source *src, const char *header, const git_oid *oid); -#define GIT_OBJECT_INCREF(ob) git_object__incref((git_object *)(ob)) +#define GIT_OBJECT_INCREF(repo, ob) git_object__incref((repo), (git_object *)(ob)) +#define GIT_OBJECT_DECREF(repo, ob) git_object__decref((repo), (git_object *)(ob)) -GIT_INLINE(void) git_object__incref(struct git_object *object) +GIT_INLINE(void) git_object__incref(git_repository *repo, struct git_object *object) { - if (object) + if (repo && repo->gc_enabled && object) object->refcount++; } +GIT_INLINE(void) git_object__decref(git_repository *repo, struct git_object *object) +{ + if (repo && repo->gc_enabled && object) + git_object_close(object); +} + #endif |
