diff options
| author | schu <schu-github@schulog.org> | 2011-08-16 09:57:43 +0200 |
|---|---|---|
| committer | schu <schu-github@schulog.org> | 2011-08-16 10:17:26 +0200 |
| commit | bcb080b00abfd6bf10ba74d1bc4546d2386d4439 (patch) | |
| tree | 1ab828924738a8819ec1361637a49231eabc4457 /src/reflog.c | |
| parent | e7be57a98bea9c56c88d8c3de78400c13909eede (diff) | |
| download | libgit2-bcb080b00abfd6bf10ba74d1bc4546d2386d4439.tar.gz | |
reflog: fix memory leaks
Make sure to free the existing reflog when we run out or memory while
adding new entries.
Signed-off-by: schu <schu-github@schulog.org>
Diffstat (limited to 'src/reflog.c')
| -rw-r--r-- | src/reflog.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/reflog.c b/src/reflog.c index 85e768123..a2dea8830 100644 --- a/src/reflog.c +++ b/src/reflog.c @@ -192,8 +192,10 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref) git_path_join_n(log_path, 3, ref->owner->path_repository, GIT_REFLOG_DIR, ref->name); - if ((error = git_futils_readbuffer(&log_file, log_path)) < GIT_SUCCESS) + if ((error = git_futils_readbuffer(&log_file, log_path)) < GIT_SUCCESS) { + git_reflog_free(log); return git__rethrow(error, "Failed to read reflog. Cannot read file `%s`", log_path); + } error = reflog_parse(log, log_file.data, log_file.len); @@ -201,6 +203,8 @@ int git_reflog_read(git_reflog **reflog, git_reference *ref) if (error == GIT_SUCCESS) *reflog = log; + else + git_reflog_free(log); return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read reflog"); } |
