Commit 0c8858de by Russell Belfer

Fix valgrind issues and leaks

This fixes up a number of problems flagged by valgrind and also
cleans up the internal `git_submodule` allocation handling
overall with a simpler model.
parent aa13bf05
......@@ -144,31 +144,40 @@ int git_buf_puts(git_buf *buf, const char *string)
int git_buf_puts_escaped(
git_buf *buf, const char *string, const char *esc_chars, const char *esc_with)
{
const char *scan = string;
size_t total = 0, esc_with_len = strlen(esc_with);
const char *scan;
size_t total = 0, esc_len = strlen(esc_with), count;
while (*scan) {
size_t count = strcspn(scan, esc_chars);
total += count + 1 + esc_with_len;
scan += count + 1;
if (!string)
return 0;
for (scan = string; *scan; ) {
/* count run of non-escaped characters */
count = strcspn(scan, esc_chars);
total += count;
scan += count;
/* count run of escaped characters */
count = strspn(scan, esc_chars);
total += count * (esc_len + 1);
scan += count;
}
ENSURE_SIZE(buf, buf->size + total + 1);
for (scan = string; *scan; ) {
size_t count = strcspn(scan, esc_chars);
count = strcspn(scan, esc_chars);
memmove(buf->ptr + buf->size, scan, count);
scan += count;
buf->size += count;
if (*scan) {
memmove(buf->ptr + buf->size, esc_with, esc_with_len);
buf->size += esc_with_len;
memmove(buf->ptr + buf->size, scan, 1);
scan += 1;
buf->size += 1;
for (count = strspn(scan, esc_chars); count > 0; --count) {
/* copy escape sequence */
memmove(buf->ptr + buf->size, esc_with, esc_len);
buf->size += esc_len;
/* copy character to be escaped */
buf->ptr[buf->size] = *scan;
buf->size++;
scan++;
}
}
......
......@@ -195,7 +195,7 @@ static int file_foreach(
void *data)
{
diskfile_backend *b = (diskfile_backend *)backend;
cvar_t *var;
cvar_t *var, *next_var;
const char *key;
regex_t regex;
int result = 0;
......@@ -212,7 +212,9 @@ static int file_foreach(
}
git_strmap_foreach(b->values, key, var,
for (; var != NULL; var = CVAR_LIST_NEXT(var)) {
for (; var != NULL; var = next_var) {
next_var = CVAR_LIST_NEXT(var);
/* skip non-matching keys if regexp was provided */
if (regexp && regexec(&regex, key, 0, NULL, 0) != 0)
continue;
......
......@@ -700,6 +700,7 @@ int git_futils_cp_r(
error = _cp_r_callback(&info, &path);
git_buf_free(&path);
git_buf_free(&info.to);
return error;
}
......@@ -253,4 +253,5 @@ void test_submodule_modify__edit_and_save(void)
(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm2));
git_repository_free(r2);
git__free(old_url);
}
{
libgit2-giterr-set-buffer
Memcheck:Leak
...
fun:git__realloc
fun:git_buf_try_grow
fun:git_buf_grow
fun:git_buf_vprintf
fun:giterr_set
}
{
mac-setenv-leak-1
Memcheck:Leak
fun:malloc_zone_malloc
fun:__setenv
fun:setenv
}
{
mac-setenv-leak-2
Memcheck:Leak
fun:malloc_zone_malloc
fun:malloc_set_zone_name
...
fun:init__zone0
fun:setenv
}
{
mac-dyld-initializer-leak
Memcheck:Leak
fun:malloc
...
fun:dyld_register_image_state_change_handler
fun:_dyld_initializer
}
{
mac-tz-leak-1
Memcheck:Leak
...
fun:token_table_add
fun:notify_register_check
fun:notify_register_tz
}
{
mac-tz-leak-2
Memcheck:Leak
fun:malloc
fun:tzload
}
{
mac-tz-leak-3
Memcheck:Leak
fun:malloc
fun:tzsetwall_basic
}
{
mac-tz-leak-4
Memcheck:Leak
fun:malloc
fun:gmtsub
}
{
mac-system-init-leak-1
Memcheck:Leak
...
fun:_libxpc_initializer
fun:libSystem_initializer
}
{
mac-system-init-leak-2
Memcheck:Leak
...
fun:__keymgr_initializer
fun:libSystem_initializer
}
{
mac-puts-leak
Memcheck:Leak
fun:malloc
fun:__smakebuf
...
fun:puts
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment