Skip to content

Commit 824ac67

Browse files
committed
remote: borrow the C string where possible
1 parent 6597495 commit 824ac67

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/remote.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ int
226226
Remote_name__set__(Remote *self, PyObject* py_name)
227227
{
228228
int err;
229-
char* name;
229+
const char* name;
230+
PyObject *tname;
230231

231-
name = py_str_to_c_str(py_name, NULL);
232+
name = py_str_borrow_c_str(&tname, py_name, NULL);
232233
if (name != NULL) {
233234
err = git_remote_rename(self->remote, name, NULL, NULL);
234-
free(name);
235+
Py_DECREF(tname);
235236

236237
if (err == GIT_OK)
237238
return 0;
@@ -404,12 +405,13 @@ int
404405
Remote_url__set__(Remote *self, PyObject* py_url)
405406
{
406407
int err;
407-
char* url = NULL;
408+
const char* url = NULL;
409+
PyObject *turl;
408410

409-
url = py_str_to_c_str(py_url, NULL);
411+
url = py_str_borrow_c_str(&turl, py_url, NULL);
410412
if (url != NULL) {
411413
err = git_remote_set_url(self->remote, url);
412-
free(url);
414+
Py_DECREF(turl);
413415

414416
if (err == GIT_OK)
415417
return 0;
@@ -440,12 +442,13 @@ int
440442
Remote_push_url__set__(Remote *self, PyObject* py_url)
441443
{
442444
int err;
443-
char* url = NULL;
445+
const char* url = NULL;
446+
PyObject *turl;
444447

445-
url = py_str_to_c_str(py_url, NULL);
448+
url = py_str_borrow_c_str(&turl, py_url, NULL);
446449
if (url != NULL) {
447450
err = git_remote_set_pushurl(self->remote, url);
448-
free(url);
451+
Py_DECREF(turl);
449452

450453
if (err == GIT_OK)
451454
return 0;

0 commit comments

Comments
 (0)