Skip to content

Commit b82656d

Browse files
committed
Merge branch 'coverity-fixes-upstream' into HEAD
2 parents 126291e + 2309852 commit b82656d

7 files changed

Lines changed: 28 additions & 15 deletions

File tree

builtin/worktree.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,14 +945,17 @@ static int add(int ac, const char **av, const char *prefix,
945945
strvec_push(&cp.args, branch);
946946
if (opt_track)
947947
strvec_push(&cp.args, opt_track);
948-
if (run_command(&cp))
949-
return -1;
948+
if (run_command(&cp)) {
949+
ret = -1;
950+
goto cleanup;
951+
}
950952
branch = new_branch;
951953
} else if (opt_track) {
952954
die(_("--[no-]track can only be used if a new branch is created"));
953955
}
954956

955957
ret = add_worktree(path, branch, &opts);
958+
cleanup:
956959
free(path);
957960
free(opt_track);
958961
free(branch_to_free);

bundle-uri.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static int download_https_uri_to_file(const char *file, const char *uri)
378378
if (child_in)
379379
fclose(child_in);
380380
if (finish_command(&cp))
381-
return 1;
381+
result = 1;
382382
if (child_out)
383383
fclose(child_out);
384384
return result;

diff-lib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
152152
continue;
153153

154154
if (ce_stage(ce)) {
155-
struct combine_diff_path *dpath;
155+
struct combine_diff_path *dpath = NULL;
156156
struct diff_filepair *pair;
157157
unsigned int wt_mode = 0;
158158
int num_compare_stages = 0;
@@ -164,6 +164,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
164164
else {
165165
if (changed < 0) {
166166
perror(ce->name);
167+
free(dpath);
167168
continue;
168169
}
169170
wt_mode = 0;

dir.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,13 +3846,18 @@ static int read_one_dir(struct untracked_cache_dir **untracked_,
38463846
ALLOC_ARRAY(ud.untracked, ud.untracked_nr);
38473847

38483848
ud.dirs_alloc = ud.dirs_nr = decode_varint(&data);
3849-
if (data > end)
3849+
if (data > end) {
3850+
free(ud.untracked);
38503851
return -1;
3852+
}
38513853
ALLOC_ARRAY(ud.dirs, ud.dirs_nr);
38523854

38533855
eos = memchr(data, '\0', end - data);
3854-
if (!eos || eos == end)
3856+
if (!eos || eos == end) {
3857+
free(ud.untracked);
3858+
free(ud.dirs);
38553859
return -1;
3860+
}
38563861

38573862
*untracked_ = untracked = xmalloc(st_add3(sizeof(*untracked), eos - data, 1));
38583863
memcpy(untracked, &ud, sizeof(ud));

line-log.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,8 +1153,7 @@ int line_log_process_ranges_arbitrary_commit(struct rev_info *rev, struct commit
11531153

11541154
if (range) {
11551155
if (commit->parents && !bloom_filter_check(rev, commit, range)) {
1156-
struct line_log_data *prange = line_log_data_copy(range);
1157-
add_line_range(rev, commit->parents->item, prange);
1156+
add_line_range(rev, commit->parents->item, range);
11581157
clear_commit_line_range(rev, commit);
11591158
} else if (commit->parents && commit->parents->next)
11601159
changed = process_ranges_merge_commit(rev, commit, range);

loose.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source
6767
struct odb_source_files *files = odb_source_files_downcast(source);
6868
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
6969
FILE *fp;
70+
int ret = -1;
7071

7172
if (!files->loose->map)
7273
loose_object_map_init(&files->loose->map);
@@ -100,13 +101,12 @@ static int load_one_loose_object_map(struct repository *repo, struct odb_source
100101
insert_loose_map(source, &oid, &compat_oid);
101102
}
102103

103-
strbuf_release(&buf);
104-
strbuf_release(&path);
105-
return errno ? -1 : 0;
104+
ret = 0;
106105
err:
106+
fclose(fp);
107107
strbuf_release(&buf);
108108
strbuf_release(&path);
109-
return -1;
109+
return ret;
110110
}
111111

112112
int repo_read_loose_object_map(struct repository *repo)
@@ -203,7 +203,8 @@ static int write_one_object(struct odb_source *source,
203203
return 0;
204204
errout:
205205
error_errno(_("failed to write loose object index %s"), path.buf);
206-
close(fd);
206+
if (fd >= 0)
207+
close(fd);
207208
rollback_lock_file(&lock);
208209
strbuf_release(&buf);
209210
strbuf_release(&path);

submodule.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,10 +2626,10 @@ int get_superproject_working_tree(struct strbuf *buf)
26262626
* We might have a superproject, but it is harder
26272627
* to determine.
26282628
*/
2629-
return 0;
2629+
goto out;
26302630

26312631
if (!strbuf_realpath(&one_up, "../", 0))
2632-
return 0;
2632+
goto out;
26332633

26342634
subpath = relative_path(cwd, one_up.buf, &sb);
26352635
strbuf_release(&one_up);
@@ -2692,6 +2692,10 @@ int get_superproject_working_tree(struct strbuf *buf)
26922692
die(_("ls-tree returned unexpected return code %d"), code);
26932693

26942694
return ret;
2695+
2696+
out:
2697+
free(cwd);
2698+
return 0;
26952699
}
26962700

26972701
/*

0 commit comments

Comments
 (0)