Skip to content

Commit e870c58

Browse files
committed
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()`
2 parents 99bbf47 + c918f5c commit e870c58

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

builtin/submodule--helper.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str
22082208
char *hex = oid_to_hex(oid);
22092209
char *remote = get_default_remote();
22102210
strvec_pushl(&cp.args, remote, hex, NULL);
2211+
free(remote);
22112212
}
22122213

22132214
return run_command(&cp);

fsmonitor-settings.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,15 @@ char *fsm_settings__get_incompatible_msg(const struct repository *r,
202202
case FSMONITOR_REASON_OK:
203203
goto done;
204204

205-
case FSMONITOR_REASON_BARE:
205+
case FSMONITOR_REASON_BARE: {
206+
char *cwd = xgetcwd();
207+
206208
strbuf_addf(&msg,
207209
_("bare repository '%s' is incompatible with fsmonitor"),
208-
xgetcwd());
210+
cwd);
211+
free(cwd);
209212
goto done;
213+
}
210214

211215
case FSMONITOR_REASON_ERROR:
212216
strbuf_addf(&msg,

pack-mtimes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static int load_pack_mtimes_file(char *mtimes_file,
8989
*data_p = data;
9090
}
9191

92-
close(fd);
92+
if (fd >= 0)
93+
close(fd);
9394
return ret;
9495
}
9596

read-cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,15 +2473,15 @@ int read_index_from(struct index_state *istate, const char *path,
24732473
the_repository, "%s", base_path);
24742474
if (!ret) {
24752475
char *path_copy = xstrdup(path);
2476-
const char *base_path2 = xstrfmt("%s/sharedindex.%s",
2477-
dirname(path_copy),
2478-
base_oid_hex);
2476+
char *base_path2 = xstrfmt("%s/sharedindex.%s",
2477+
dirname(path_copy), base_oid_hex);
24792478
free(path_copy);
24802479
trace2_region_enter_printf("index", "shared/do_read_index",
24812480
the_repository, "%s", base_path2);
24822481
ret = do_read_index(split_index->base, base_path2, 1);
24832482
trace2_region_leave_printf("index", "shared/do_read_index",
24842483
the_repository, "%s", base_path2);
2484+
free(base_path2);
24852485
}
24862486
if (!oideq(&split_index->base_oid, &split_index->base->oid))
24872487
die(_("broken index, expect %s in %s, got %s"),

remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ char *relative_url(const char *remote_url, const char *url,
28462846
* When the url starts with '../', remove that and the
28472847
* last directory in remoteurl.
28482848
*/
2849-
while (url) {
2849+
while (*url) {
28502850
if (starts_with_dot_dot_slash_native(url)) {
28512851
url += 3;
28522852
colonsep |= chop_last_dir(&remoteurl, is_relative);

submodule-config.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,10 @@ static void traverse_tree_submodules(struct repository *r,
756756

757757
if (S_ISGITLINK(name_entry->mode) &&
758758
is_tree_submodule_active(r, root_tree, tree_path)) {
759-
st_entry = xmalloc(sizeof(*st_entry));
759+
ALLOC_GROW(out->entries, out->entry_nr + 1,
760+
out->entry_alloc);
761+
st_entry = &out->entries[out->entry_nr++];
762+
760763
st_entry->name_entry = xmalloc(sizeof(*st_entry->name_entry));
761764
*st_entry->name_entry = *name_entry;
762765
st_entry->submodule =
@@ -766,9 +769,6 @@ static void traverse_tree_submodules(struct repository *r,
766769
root_tree))
767770
FREE_AND_NULL(st_entry->repo);
768771

769-
ALLOC_GROW(out->entries, out->entry_nr + 1,
770-
out->entry_alloc);
771-
out->entries[out->entry_nr++] = *st_entry;
772772
} else if (S_ISDIR(name_entry->mode))
773773
traverse_tree_submodules(r, root_tree, tree_path,
774774
&name_entry->oid, out);

0 commit comments

Comments
 (0)