Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e7a3b317
Commit
e7a3b317
authored
Aug 17, 2011
by
schu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reflog.c: fix memory leaks
Signed-off-by: schu <schu-github@schulog.org>
parent
31e59092
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
8 deletions
+21
-8
src/reflog.c
+21
-8
No files found.
src/reflog.c
View file @
e7a3b317
...
@@ -102,8 +102,12 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -102,8 +102,12 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
git_reflog_entry
*
entry
;
git_reflog_entry
*
entry
;
#define seek_forward(_increase) { \
#define seek_forward(_increase) { \
if (_increase >= buf_size) \
if (_increase >= buf_size) { \
if (entry->committer) \
free(entry->committer); \
free(entry); \
return git__throw(GIT_ERROR, "Failed to seek forward. Buffer size exceeded"); \
return git__throw(GIT_ERROR, "Failed to seek forward. Buffer size exceeded"); \
} \
buf += _increase; \
buf += _increase; \
buf_size -= _increase; \
buf_size -= _increase; \
}
}
...
@@ -112,13 +116,18 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -112,13 +116,18 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
entry
=
git__malloc
(
sizeof
(
git_reflog_entry
));
entry
=
git__malloc
(
sizeof
(
git_reflog_entry
));
if
(
entry
==
NULL
)
if
(
entry
==
NULL
)
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
entry
->
committer
=
NULL
;
if
(
git_oid_fromstrn
(
&
entry
->
oid_old
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
if
(
git_oid_fromstrn
(
&
entry
->
oid_old
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
{
free
(
entry
);
return
GIT_ERROR
;
return
GIT_ERROR
;
}
seek_forward
(
GIT_OID_HEXSZ
+
1
);
seek_forward
(
GIT_OID_HEXSZ
+
1
);
if
(
git_oid_fromstrn
(
&
entry
->
oid_cur
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
if
(
git_oid_fromstrn
(
&
entry
->
oid_cur
,
buf
,
GIT_OID_HEXSZ
)
<
GIT_SUCCESS
)
{
free
(
entry
);
return
GIT_ERROR
;
return
GIT_ERROR
;
}
seek_forward
(
GIT_OID_HEXSZ
+
1
);
seek_forward
(
GIT_OID_HEXSZ
+
1
);
ptr
=
buf
;
ptr
=
buf
;
...
@@ -128,11 +137,16 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -128,11 +137,16 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
seek_forward
(
1
);
seek_forward
(
1
);
entry
->
committer
=
git__malloc
(
sizeof
(
git_signature
));
entry
->
committer
=
git__malloc
(
sizeof
(
git_signature
));
if
(
entry
->
committer
==
NULL
)
if
(
entry
->
committer
==
NULL
)
{
free
(
entry
);
return
GIT_ENOMEM
;
return
GIT_ENOMEM
;
}
if
((
error
=
git_signature__parse
(
entry
->
committer
,
&
ptr
,
buf
+
1
,
NULL
,
*
buf
))
<
GIT_SUCCESS
)
if
((
error
=
git_signature__parse
(
entry
->
committer
,
&
ptr
,
buf
+
1
,
NULL
,
*
buf
))
<
GIT_SUCCESS
)
{
goto
cleanup
;
free
(
entry
->
committer
);
free
(
entry
);
return
git__rethrow
(
error
,
"Failed to parse reflog. Could not parse signature"
);
}
if
(
*
buf
==
'\t'
)
{
if
(
*
buf
==
'\t'
)
{
/* We got a message. Read everything till we reach LF. */
/* We got a message. Read everything till we reach LF. */
...
@@ -150,12 +164,11 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
...
@@ -150,12 +164,11 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
seek_forward
(
1
);
seek_forward
(
1
);
if
((
error
=
git_vector_insert
(
&
log
->
entries
,
entry
))
<
GIT_SUCCESS
)
if
((
error
=
git_vector_insert
(
&
log
->
entries
,
entry
))
<
GIT_SUCCESS
)
goto
cleanup
;
return
git__rethrow
(
error
,
"Failed to parse reflog. Could not add new entry"
)
;
}
}
#undef seek_forward
#undef seek_forward
cleanup:
return
error
==
GIT_SUCCESS
?
GIT_SUCCESS
:
git__rethrow
(
error
,
"Failed to parse reflog"
);
return
error
==
GIT_SUCCESS
?
GIT_SUCCESS
:
git__rethrow
(
error
,
"Failed to parse reflog"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment