Commit cc48ea6
committed
Fix ownership and error handling bugs in refdb backend callbacks
pygit2_refdb_backend_write() wrapped libgit2's reference and
signature pointers directly, so the Python objects freed memory that
libgit2 frees again on return, a double free. Pass git_reference_dup()
and git_signature_dup() copies instead.
It also fed the _old OID pointer straight into git_oid_to_python(),
crashing when libgit2 passes NULL for newly created references; map
NULL to None, which RefdbBackend.write() already accepts.
pygit2_refdb_backend_lookup() treated a None result as a type error,
but None is how RefdbBackend.lookup() signals 'not found'; translate
it to GIT_ENOTFOUND.
Both lookup() and rename() leaked the Python Reference returned by
the callback, because libgit2 takes ownership of the underlying
git_reference while Reference_dealloc() would free it too. Detach
the pointer from the Python object before releasing it.
Add test_write_callback and test_write_callback_create, driving the
write callback through libgit2's git_reference_set_target() and
git_reference_create().
Follow-up to the fix for #1474
Assisted-by: Kimi Code1 parent 997c65b commit cc48ea6
2 files changed
Lines changed: 77 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
194 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
195 | 203 | | |
196 | 204 | | |
197 | 205 | | |
198 | | - | |
199 | | - | |
| 206 | + | |
| 207 | + | |
200 | 208 | | |
201 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
202 | 213 | | |
203 | | - | |
204 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
205 | 217 | | |
206 | 218 | | |
207 | 219 | | |
| |||
212 | 224 | | |
213 | 225 | | |
214 | 226 | | |
215 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
216 | 236 | | |
| 237 | + | |
217 | 238 | | |
218 | 239 | | |
219 | 240 | | |
220 | | - | |
221 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
222 | 244 | | |
223 | | - | |
| 245 | + | |
224 | 246 | | |
225 | 247 | | |
226 | | - | |
227 | | - | |
| 248 | + | |
| 249 | + | |
228 | 250 | | |
229 | | - | |
230 | 251 | | |
231 | 252 | | |
232 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
233 | 267 | | |
234 | 268 | | |
235 | 269 | | |
| |||
239 | 273 | | |
240 | 274 | | |
241 | 275 | | |
242 | | - | |
| 276 | + | |
243 | 277 | | |
244 | 278 | | |
245 | 279 | | |
| |||
277 | 311 | | |
278 | 312 | | |
279 | 313 | | |
| 314 | + | |
280 | 315 | | |
281 | 316 | | |
282 | 317 | | |
| |||
287 | 322 | | |
288 | 323 | | |
289 | 324 | | |
290 | | - | |
291 | | - | |
| 325 | + | |
| 326 | + | |
292 | 327 | | |
| 328 | + | |
| 329 | + | |
293 | 330 | | |
294 | 331 | | |
295 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
139 | 163 | | |
140 | 164 | | |
141 | 165 | | |
| |||
0 commit comments