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()`
This commit is contained in:
Junio C Hamano 2022-06-17 10:33:31 -07:00
commit e870c5857f
6 changed files with 17 additions and 11 deletions

View File

@ -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);

View File

@ -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,

View File

@ -89,7 +89,8 @@ cleanup:
*data_p = data;
}
close(fd);
if (fd >= 0)
close(fd);
return ret;
}

View File

@ -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"),

View File

@ -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);

View File

@ -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);