Ticket #4259: 4259-fix-reference-leak.patch

File 4259-fix-reference-leak.patch, 1.3 KB (added by Matthew Bradbury <matt-bradbury@…>, 12 years ago)
  • libs/python/src/object/function.cpp

     
    433433    if (attribute.ptr()->ob_type == &function_type)
    434434    {
    435435        function* new_func = downcast<function>(attribute.ptr());
    436         PyObject* dict = 0;
     436        handle<> dict;
    437437       
    438438#if PY_VERSION_HEX < 0x03000000
    439439        // Old-style class gone in Python 3
    440440        if (PyClass_Check(ns))
    441             dict = ((PyClassObject*)ns)->cl_dict;
     441            dict = handle<>(borrowed(((PyClassObject*)ns)->cl_dict));
    442442        else
    443443#endif       
    444444        if (PyType_Check(ns))
    445             dict = ((PyTypeObject*)ns)->tp_dict;
     445            dict = handle<>(borrowed(((PyTypeObject*)ns)->tp_dict));
    446446        else   
    447             dict = PyObject_GetAttrString(ns, const_cast<char*>("__dict__"));
     447            dict = handle<>(PyObject_GetAttrString(ns, const_cast<char*>("__dict__")));
    448448
    449449        if (dict == 0)
    450450            throw_error_already_set();
    451451
    452         handle<> existing(allow_null(::PyObject_GetItem(dict, name.ptr())));
     452        handle<> existing(allow_null(::PyObject_GetItem(dict.get(), name.ptr())));
    453453       
    454454        if (existing)
    455455        {