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
b709e951
Commit
b709e951
authored
May 04, 2012
by
Russell Belfer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix memory leaks and use after free
parent
f917481e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
19 deletions
+37
-19
include/git2/attr.h
+3
-3
src/attr.c
+3
-2
src/config_file.c
+1
-0
src/diff.c
+8
-4
src/ignore.c
+1
-1
src/strmap.h
+19
-9
tests-clar/diff/tree.c
+2
-0
No files found.
include/git2/attr.h
View file @
b709e951
...
...
@@ -160,10 +160,10 @@ GIT_EXTERN(int) git_attr_get(
* array itself if you allocated it).
*/
GIT_EXTERN
(
int
)
git_attr_get_many
(
git_repository
*
repo
,
git_repository
*
repo
,
uint32_t
flags
,
const
char
*
path
,
size_t
num_attr
,
size_t
num_attr
,
const
char
**
names
,
const
char
**
values
);
...
...
@@ -186,7 +186,7 @@ GIT_EXTERN(int) git_attr_get_many(
* @param payload Passed on as extra parameter to callback function.
*/
GIT_EXTERN
(
int
)
git_attr_foreach
(
git_repository
*
repo
,
git_repository
*
repo
,
uint32_t
flags
,
const
char
*
path
,
int
(
*
callback
)(
const
char
*
name
,
const
char
*
value
,
void
*
payload
),
...
...
src/attr.c
View file @
b709e951
...
...
@@ -334,8 +334,6 @@ int git_attr_cache__push_file(
}
/* if not in cache, load data, parse, and cache */
if
(
git_attr_file__new
(
&
file
,
source
,
relfile
,
&
cache
->
pool
)
<
0
)
return
-
1
;
if
(
source
==
GIT_ATTR_FILE_FROM_FILE
)
error
=
load_attr_file
(
filename
,
&
content
);
...
...
@@ -354,6 +352,9 @@ int git_attr_cache__push_file(
if
(
blob
)
content
=
git_blob_rawcontent
(
blob
);
if
((
error
=
git_attr_file__new
(
&
file
,
source
,
relfile
,
&
cache
->
pool
))
<
0
)
goto
finish
;
if
(
parse
&&
(
error
=
parse
(
repo
,
content
,
file
))
<
0
)
goto
finish
;
...
...
src/config_file.c
View file @
b709e951
...
...
@@ -265,6 +265,7 @@ static int config_set(git_config_file *cfg, const char *name, const char *value)
cvar_free
(
old_var
);
if
(
config_write
(
b
,
key
,
NULL
,
value
)
<
0
)
{
git_strmap_delete
(
b
->
values
,
var
->
key
);
cvar_free
(
var
);
return
-
1
;
}
...
...
src/diff.c
View file @
b709e951
...
...
@@ -506,7 +506,7 @@ static int diff_from_iterators(
git_diff_list
**
diff_ptr
)
{
const
git_index_entry
*
oitem
,
*
nitem
;
char
*
ignore_prefix
=
NULL
;
git_buf
ignore_prefix
=
GIT_BUF_INIT
;
git_diff_list
*
diff
=
git_diff_list_alloc
(
repo
,
opts
);
if
(
!
diff
)
goto
fail
;
...
...
@@ -536,8 +536,8 @@ static int diff_from_iterators(
git_delta_t
delta_type
=
GIT_DELTA_ADDED
;
/* contained in ignored parent directory, so this can be skipped. */
if
(
ignore_prefix
!=
NULL
&&
git__prefixcmp
(
nitem
->
path
,
ignore_prefix
)
==
0
)
if
(
git_buf_len
(
&
ignore_prefix
)
&&
git__prefixcmp
(
nitem
->
path
,
git_buf_cstr
(
&
ignore_prefix
)
)
==
0
)
{
if
(
git_iterator_advance
(
new_iter
,
&
nitem
)
<
0
)
goto
fail
;
...
...
@@ -555,7 +555,7 @@ static int diff_from_iterators(
(
oitem
&&
git__prefixcmp
(
oitem
->
path
,
nitem
->
path
)
==
0
))
{
if
(
is_ignored
)
ignore_prefix
=
nitem
->
path
;
git_buf_sets
(
&
ignore_prefix
,
nitem
->
path
)
;
if
(
git_iterator_advance_into_directory
(
new_iter
,
&
nitem
)
<
0
)
goto
fail
;
...
...
@@ -589,12 +589,16 @@ static int diff_from_iterators(
git_iterator_free
(
old_iter
);
git_iterator_free
(
new_iter
);
git_buf_free
(
&
ignore_prefix
);
*
diff_ptr
=
diff
;
return
0
;
fail:
git_iterator_free
(
old_iter
);
git_iterator_free
(
new_iter
);
git_buf_free
(
&
ignore_prefix
);
git_diff_list_free
(
diff
);
*
diff_ptr
=
NULL
;
return
-
1
;
...
...
src/ignore.c
View file @
b709e951
...
...
@@ -8,7 +8,7 @@
static
int
parse_ignore_file
(
git_repository
*
repo
,
const
char
*
buffer
,
git_attr_file
*
ignores
)
{
int
error
;
int
error
=
0
;
git_attr_fnmatch
*
match
=
NULL
;
const
char
*
scan
=
NULL
;
char
*
context
=
NULL
;
...
...
src/strmap.h
View file @
b709e951
...
...
@@ -36,18 +36,28 @@ typedef khash_t(str) git_strmap;
#define git_strmap_set_value_at(h, idx, v) kh_val(h, idx) = v
#define git_strmap_delete_at(h, idx) kh_del(str, h, idx)
#define git_strmap_insert(h, key, val, err) do { \
khiter_t __pos = kh_put(str, h, key, &err); \
if (err >= 0) kh_val(h, __pos) = val; \
} while (0)
#define git_strmap_insert2(h, key, val, old, err) do { \
khiter_t __pos = kh_put(str, h, key, &err); \
if (err >= 0) { \
old = (err == 0) ? kh_val(h, __pos) : NULL; \
#define git_strmap_insert(h, key, val, rval) do { \
khiter_t __pos = kh_put(str, h, key, &rval); \
if (rval >= 0) { \
if (rval == 0) kh_key(h, __pos) = key; \
kh_val(h, __pos) = val; \
} } while (0)
#define git_strmap_insert2(h, key, val, oldv, rval) do { \
khiter_t __pos = kh_put(str, h, key, &rval); \
if (rval >= 0) { \
if (rval == 0) { \
oldv = kh_val(h, __pos); \
kh_key(h, __pos) = key; \
} else { oldv = NULL; } \
kh_val(h, __pos) = val; \
} } while (0)
#define git_strmap_delete(h, key) do { \
khiter_t __pos = git_strmap_lookup_index(h, key); \
if (git_strmap_valid_index(h, __pos)) \
git_strmap_delete_at(h, __pos); } while (0)
#define git_strmap_foreach kh_foreach
#define git_strmap_foreach_value kh_foreach_value
...
...
tests-clar/diff/tree.c
View file @
b709e951
...
...
@@ -205,4 +205,6 @@ void test_diff_tree__bare(void)
cl_assert
(
exp
.
line_dels
==
1
);
git_diff_list_free
(
diff
);
git_tree_free
(
a
);
git_tree_free
(
b
);
}
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