forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9cda81f
committed
Be more careful about Python refcounts while creating exception objects.
PLy_generate_spi_exceptions neglected to do Py_INCREF on the new exceptionobjects, evidently supposing that PyModule_AddObject would do that --- butit doesn't. This left us in a situation where a Python garbage collectioncycle could result in deletion of exception object(s), causing servercrashes or wrong answers if the exception objects are used later in thesession.In addition, PLy_generate_spi_exceptions didn't bother to test fora null result from PyErr_NewException, which at best is inconsistentwith the code in PLy_add_exceptions. And PLy_add_exceptions, while itdid do Py_INCREF on the exceptions it makes, waited to do that tillafter some PyModule_AddObject calls, creating a similar risk forfailure if garbage collection happened within those calls.To fix, refactor to have just one piece of code that creates anexception object and adds it to the spiexceptions module, bumping therefcount first.Also, let's add an additional refcount to represent the pointer we'regoing to store in a C global variable or hash table. This should onlymatter if the user does something weird like delete the spiexceptionsPython module, but lack of paranoia has caused us enough problems inPL/Python already.The fact that PyModule_AddObject doesn't do a Py_INCREF of its ownexplains the need for the Py_INCREF added in commit4c966d9, so wecan improve the comment about that; also, this means we really wantto do that before not after the PyModule_AddObject call.The missing Py_INCREF in PLy_generate_spi_exceptions was reported anddiagnosed by Rafa de la Torre; the other fixes by me. Back-patchto all supported branches.Discussion:https://postgr.es/m/CA+Fz15kR1OXZv43mDrJb3XY+1MuQYWhx5kx3ea6BRKQp6ezGkg@mail.gmail.com1 parenta73491e commit9cda81f
1 file changed
+50
-29
lines changedLines changed: 50 additions & 29 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
25 | 25 |
| |
26 | 26 |
| |
27 | 27 |
| |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 |
| |
29 | 32 |
| |
30 | 33 |
| |
| |||
192 | 195 |
| |
193 | 196 |
| |
194 | 197 |
| |
195 |
| - | |
196 |
| - | |
| 198 | + | |
| 199 | + | |
197 | 200 |
| |
198 | 201 |
| |
199 |
| - | |
200 |
| - | |
201 |
| - | |
202 |
| - | |
203 |
| - | |
204 |
| - | |
205 |
| - | |
206 |
| - | |
| 202 | + | |
| 203 | + | |
207 | 204 |
| |
208 | 205 |
| |
| 206 | + | |
| 207 | + | |
209 | 208 |
| |
210 |
| - | |
211 |
| - | |
212 |
| - | |
213 |
| - | |
214 |
| - | |
215 |
| - | |
216 |
| - | |
217 |
| - | |
218 |
| - | |
219 |
| - | |
220 |
| - | |
221 |
| - | |
222 |
| - | |
223 |
| - | |
224 |
| - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
225 | 215 |
| |
226 | 216 |
| |
227 | 217 |
| |
228 | 218 |
| |
229 |
| - | |
| 219 | + | |
230 | 220 |
| |
231 | 221 |
| |
232 | 222 |
| |
233 | 223 |
| |
234 | 224 |
| |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
235 | 254 |
| |
236 | 255 |
| |
237 | 256 |
| |
| |||
257 | 276 |
| |
258 | 277 |
| |
259 | 278 |
| |
260 |
| - | |
261 |
| - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
262 | 283 |
| |
263 | 284 |
| |
264 |
| - | |
265 | 285 |
| |
| 286 | + | |
266 | 287 |
| |
267 | 288 |
| |
268 | 289 |
| |
|
0 commit comments
Comments
(0)