Skip to content

Commit bb42484

Browse files
committed
Merge branch 'rs/remote-leakfix'
Leakfix. * rs/remote-leakfix: remote: plug memory leaks at early returns
2 parents 17636cd + 4e7aa34 commit bb42484

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

builtin/remote.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static int add(int argc, const char **argv, const char *prefix)
164164
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
165165
const char *name, *url;
166166
int i;
167+
int result = 0;
167168

168169
struct option options[] = {
169170
OPT_BOOL('f', "fetch", &fetch, N_("fetch the remote branches")),
@@ -230,8 +231,10 @@ static int add(int argc, const char **argv, const char *prefix)
230231
fetch_tags == TAGS_SET ? "--tags" : "--no-tags");
231232
}
232233

233-
if (fetch && fetch_remote(name))
234-
return 1;
234+
if (fetch && fetch_remote(name)) {
235+
result = 1;
236+
goto out;
237+
}
235238

236239
if (master) {
237240
strbuf_reset(&buf);
@@ -241,14 +244,15 @@ static int add(int argc, const char **argv, const char *prefix)
241244
strbuf_addf(&buf2, "refs/remotes/%s/%s", name, master);
242245

243246
if (refs_update_symref(get_main_ref_store(the_repository), buf.buf, buf2.buf, "remote add"))
244-
return error(_("Could not setup master '%s'"), master);
247+
result = error(_("Could not setup master '%s'"), master);
245248
}
246249

250+
out:
247251
strbuf_release(&buf);
248252
strbuf_release(&buf2);
249253
string_list_clear(&track, 0);
250254

251-
return 0;
255+
return result;
252256
}
253257

254258
struct branch_info {
@@ -715,6 +719,7 @@ static int mv(int argc, const char **argv, const char *prefix)
715719
struct rename_info rename;
716720
int i, refs_renamed_nr = 0, refspec_updated = 0;
717721
struct progress *progress = NULL;
722+
int result = 0;
718723

719724
argc = parse_options(argc, argv, prefix, options,
720725
builtin_remote_rename_usage, 0);
@@ -747,9 +752,11 @@ static int mv(int argc, const char **argv, const char *prefix)
747752

748753
strbuf_addf(&buf, "remote.%s", rename.old_name);
749754
strbuf_addf(&buf2, "remote.%s", rename.new_name);
750-
if (repo_config_rename_section(the_repository, buf.buf, buf2.buf) < 1)
751-
return error(_("Could not rename config section '%s' to '%s'"),
752-
buf.buf, buf2.buf);
755+
if (repo_config_rename_section(the_repository, buf.buf, buf2.buf) < 1) {
756+
result = error(_("Could not rename config section '%s' to '%s'"),
757+
buf.buf, buf2.buf);
758+
goto out;
759+
}
753760

754761
if (oldremote->fetch.raw_nr) {
755762
strbuf_reset(&buf);
@@ -870,7 +877,7 @@ static int mv(int argc, const char **argv, const char *prefix)
870877
strbuf_release(&buf);
871878
strbuf_release(&buf2);
872879
strbuf_release(&buf3);
873-
return 0;
880+
return result;
874881
}
875882

876883
static int rm(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)