mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 23:26:39 +00:00
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>
This commit is contained in:
parent
e7be57a98b
commit
bcb080b00a
@ -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);
|
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);
|
return git__rethrow(error, "Failed to read reflog. Cannot read file `%s`", log_path);
|
||||||
|
}
|
||||||
|
|
||||||
error = reflog_parse(log, log_file.data, log_file.len);
|
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)
|
if (error == GIT_SUCCESS)
|
||||||
*reflog = log;
|
*reflog = log;
|
||||||
|
else
|
||||||
|
git_reflog_free(log);
|
||||||
|
|
||||||
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read reflog");
|
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read reflog");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user