aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-06-17 10:33:31 -0700
committerJunio C Hamano <gitster@pobox.com>2022-06-17 10:33:31 -0700
commite870c5857fbd67a7015b8c5539293bcb5d8e8ff5 (patch)
tree83d6d4dba0207548c67cebdf7a6b39d9e116384f
parentMerge branch 'jc/cocci-cleanup' (diff)
parentrelative_url(): fix incorrect condition (diff)
downloadgit-e870c5857fbd67a7015b8c5539293bcb5d8e8ff5.tar.gz
git-e870c5857fbd67a7015b8c5539293bcb5d8e8ff5.zip
Merge branch 'js/misc-fixes'
Assorted fixes to problems found by Coverity. * js/misc-fixes: relative_url(): fix incorrect condition pack-mtimes: avoid closing a bogus file descriptor read_index_from(): avoid memory leak submodule--helper: avoid memory leak when fetching submodules submodule-config: avoid memory leak fsmonitor: avoid memory leak in `fsm_settings__get_incompatible_msg()`
-rw-r--r--builtin/submodule--helper.c1
-rw-r--r--fsmonitor-settings.c8
-rw-r--r--pack-mtimes.c3
-rw-r--r--read-cache.c6
-rw-r--r--remote.c2
-rw-r--r--submodule-config.c8
6 files changed, 17 insertions, 11 deletions
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 5c77dfcffe..c597df7528 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -2208,6 +2208,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str
char *hex = oid_to_hex(oid);
char *remote = get_default_remote();
strvec_pushl(&cp.args, remote, hex, NULL);
+ free(remote);
}
return run_command(&cp);
diff --git a/fsmonitor-settings.c b/fsmonitor-settings.c
index 658cb79da0..464424a1e9 100644
--- a/fsmonitor-settings.c
+++ b/fsmonitor-settings.c
@@ -202,11 +202,15 @@ char *fsm_settings__get_incompatible_msg(const struct repository *r,
case FSMONITOR_REASON_OK:
goto done;
- case FSMONITOR_REASON_BARE:
+ case FSMONITOR_REASON_BARE: {
+ char *cwd = xgetcwd();
+
strbuf_addf(&msg,
_("bare repository '%s' is incompatible with fsmonitor"),
- xgetcwd());
+ cwd);
+ free(cwd);
goto done;
+ }
case FSMONITOR_REASON_ERROR:
strbuf_addf(&msg,
diff --git a/pack-mtimes.c b/pack-mtimes.c
index 0e0aafdcb0..0f9785fc5e 100644
--- a/pack-mtimes.c
+++ b/pack-mtimes.c
@@ -89,7 +89,8 @@ cleanup:
*data_p = data;
}
- close(fd);
+ if (fd >= 0)
+ close(fd);
return ret;
}
diff --git a/read-cache.c b/read-cache.c
index e61af3a3d4..76f372ff91 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2473,15 +2473,15 @@ int read_index_from(struct index_state *istate, const char *path,
the_repository, "%s", base_path);
if (!ret) {
char *path_copy = xstrdup(path);
- const char *base_path2 = xstrfmt("%s/sharedindex.%s",
- dirname(path_copy),
- base_oid_hex);
+ char *base_path2 = xstrfmt("%s/sharedindex.%s",
+ dirname(path_copy), base_oid_hex);
free(path_copy);
trace2_region_enter_printf("index", "shared/do_read_index",
the_repository, "%s", base_path2);
ret = do_read_index(split_index->base, base_path2, 1);
trace2_region_leave_printf("index", "shared/do_read_index",
the_repository, "%s", base_path2);
+ free(base_path2);
}
if (!oideq(&split_index->base_oid, &split_index->base->oid))
die(_("broken index, expect %s in %s, got %s"),
diff --git a/remote.c b/remote.c
index 9b9bbfe80e..bded6acbfe 100644
--- a/remote.c
+++ b/remote.c
@@ -2846,7 +2846,7 @@ char *relative_url(const char *remote_url, const char *url,
* When the url starts with '../', remove that and the
* last directory in remoteurl.
*/
- while (url) {
+ while (*url) {
if (starts_with_dot_dot_slash_native(url)) {
url += 3;
colonsep |= chop_last_dir(&remoteurl, is_relative);
diff --git a/submodule-config.c b/submodule-config.c
index ce3beaf5d4..51ecbe901e 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -756,7 +756,10 @@ static void traverse_tree_submodules(struct repository *r,
if (S_ISGITLINK(name_entry->mode) &&
is_tree_submodule_active(r, root_tree, tree_path)) {
- st_entry = xmalloc(sizeof(*st_entry));
+ ALLOC_GROW(out->entries, out->entry_nr + 1,
+ out->entry_alloc);
+ st_entry = &out->entries[out->entry_nr++];
+
st_entry->name_entry = xmalloc(sizeof(*st_entry->name_entry));
*st_entry->name_entry = *name_entry;
st_entry->submodule =
@@ -766,9 +769,6 @@ static void traverse_tree_submodules(struct repository *r,
root_tree))
FREE_AND_NULL(st_entry->repo);
- ALLOC_GROW(out->entries, out->entry_nr + 1,
- out->entry_alloc);
- out->entries[out->entry_nr++] = *st_entry;
} else if (S_ISDIR(name_entry->mode))
traverse_tree_submodules(r, root_tree, tree_path,
&name_entry->oid, out);