in ctx.c
the objects saved in "ctx_list" aren't ref counted.
the object saved in "global_ctx_object" is incref'ed by set_global_ctx() but never decref'ed.
i can send a C example that causes seg faults if needed.
i'm attaching a possible patch but i haven't properly looked at all the original code to see if it's correct or breaks anything else.
also Cursor.__del__ and Connection.__del__ reference global variables that might be freed before the object itself.
patch for ctx.c