@@ -105,15 +105,16 @@ PyDoc_STRVAR(Refspec_src_matches__doc__,
105
105
PyObject *
106
106
Refspec_src_matches (Refspec * self , PyObject * py_str )
107
107
{
108
- char * str ;
108
+ const char * str ;
109
+ PyObject * tstr ;
109
110
int res ;
110
111
111
- str = py_str_to_c_str ( py_str , NULL );
112
+ str = py_str_borrow_c_str ( & tstr , py_str , NULL );
112
113
if (!str )
113
114
return NULL ;
114
115
115
116
res = git_refspec_src_matches (self -> refspec , str );
116
- free ( str );
117
+ Py_DECREF ( tstr );
117
118
118
119
if (res )
119
120
Py_RETURN_TRUE ;
@@ -129,15 +130,16 @@ PyDoc_STRVAR(Refspec_dst_matches__doc__,
129
130
PyObject *
130
131
Refspec_dst_matches (Refspec * self , PyObject * py_str )
131
132
{
132
- char * str ;
133
+ const char * str ;
134
+ PyObject * tstr ;
133
135
int res ;
134
136
135
- str = py_str_to_c_str ( py_str , NULL );
137
+ str = py_str_borrow_c_str ( & tstr , py_str , NULL );
136
138
if (!str )
137
139
return NULL ;
138
140
139
141
res = git_refspec_dst_matches (self -> refspec , str );
140
- free ( str );
142
+ Py_DECREF ( tstr );
141
143
142
144
if (res )
143
145
Py_RETURN_TRUE ;
@@ -153,24 +155,25 @@ PyDoc_STRVAR(Refspec_transform__doc__,
153
155
PyObject *
154
156
Refspec_transform (Refspec * self , PyObject * py_str )
155
157
{
156
- char * str , * trans ;
158
+ const char * str ;
159
+ char * trans ;
157
160
int err , len , alen ;
158
- PyObject * py_trans ;
161
+ PyObject * py_trans , * tstr ;
159
162
160
- str = py_str_to_c_str ( py_str , NULL );
163
+ str = py_str_borrow_c_str ( & tstr , py_str , NULL );
161
164
alen = len = strlen (str );
162
165
163
166
do {
164
167
alen *= alen ;
165
168
trans = malloc (alen );
166
169
if (!trans ) {
167
- free ( str );
170
+ Py_DECREF ( tstr );
168
171
return PyErr_NoMemory ();
169
172
}
170
173
171
174
err = git_refspec_transform (trans , alen , self -> refspec , str );
172
175
} while (err == GIT_EBUFS );
173
- free ( str );
176
+ Py_DECREF ( tstr );
174
177
175
178
if (err < 0 ) {
176
179
free (trans );
@@ -193,24 +196,25 @@ PyDoc_STRVAR(Refspec_rtransform__doc__,
193
196
PyObject *
194
197
Refspec_rtransform (Refspec * self , PyObject * py_str )
195
198
{
196
- char * str , * trans ;
199
+ const char * str ;
200
+ char * trans ;
197
201
int err , len , alen ;
198
- PyObject * py_trans ;
202
+ PyObject * py_trans , * tstr ;
199
203
200
- str = py_str_to_c_str ( py_str , NULL );
204
+ str = py_str_borrow_c_str ( & tstr , py_str , NULL );
201
205
alen = len = strlen (str );
202
206
203
207
do {
204
208
alen *= alen ;
205
209
trans = malloc (alen );
206
210
if (!trans ) {
207
- free ( str );
211
+ Py_DECREF ( tstr );
208
212
return PyErr_NoMemory ();
209
213
}
210
214
211
215
err = git_refspec_rtransform (trans , alen , self -> refspec , str );
212
216
} while (err == GIT_EBUFS );
213
- free ( str );
217
+ Py_DECREF ( tstr );
214
218
215
219
if (err < 0 ) {
216
220
free (trans );
0 commit comments