- Notifications
You must be signed in to change notification settings - Fork5.3k
Commit7fb8c92
committed
Fix resource leaks in PL/Python error reporting, redux.
Commitc6f7f11 intended to prevent leaking any PyObject referencecounts in edge cases (such as out-of-memory during stringconstruction), but actually it introduced a leak in the normal case.Repeating an error-trapping operation often enough would lead tosession-lifespan memory bloat. The problem is that I failed tothink about the fact that PyObject_GetAttrString() increments therefcount of the returned PyObject, so that simply walking down thelist of error frame objects causes all but the first one to havetheir refcount incremented.I experimented with several more-or-less-complex ways around that,and eventually concluded that the right fix is simply to drop thenewly-obtained refcount as soon as we walk to the next frameobject in PLy_traceback. This sounds unsafe, but it's perfectlyokay because the caller holds a refcount on the first frame objectand each frame object holds a refcount on the next one; so thecurrent frame object can't disappear underneath us.By the same token, we can simplify the caller's cleanup back tosimply dropping its refcount on the first object. Cleanup ofeach frame object will lead in turn to the refcount of the nextone going to zero.I also added a couple of comments explaining why PLy_elog_impl()doesn't try to free the strings acquired from PLy_get_spi_error_data()or PLy_get_error_data(). That's because I got here by looking at aCoverity complaint about how those strings might get leaked. Theyare not leaked, but in testing that I discovered this other leak.Back-patch, asc6f7f11 was. It's a bit nervous-making to beputting such a fix into v13, which is only a couple weeks from itsfinal release; but I can't see that leaving a recently-introducedleak in place is a better idea.Author: Tom Lane <tgl@sss.pgh.pa.us>Discussion:https://postgr.es/m/1203918.1761184159@sss.pgh.pa.usBackpatch-through: 131 parent10799d0 commit7fb8c92
1 file changed
+21
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
| 146 | + | |
154 | 147 | | |
155 | 148 | | |
156 | 149 | | |
| |||
347 | 340 | | |
348 | 341 | | |
349 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
350 | 354 | | |
351 | 355 | | |
352 | 356 | | |
| |||
380 | 384 | | |
381 | 385 | | |
382 | 386 | | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
383 | 391 | | |
384 | 392 | | |
385 | 393 | | |
| |||
416 | 424 | | |
417 | 425 | | |
418 | 426 | | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
419 | 432 | | |
420 | 433 | | |
421 | 434 | | |
| |||
0 commit comments
Comments
(0)