@@ -780,34 +780,47 @@ _lsprof_Profiler_enable_impl(ProfilerObject *self, int subcalls,
780
780
return NULL ;
781
781
}
782
782
783
- if (PyObject_CallMethod (monitoring , "use_tool_id" , "is" , self -> tool_id , "cProfile" ) == NULL ) {
783
+ PyObject * check = PyObject_CallMethod (monitoring ,
784
+ "use_tool_id" , "is" ,
785
+ self -> tool_id , "cProfile" );
786
+ if (check == NULL ) {
784
787
PyErr_Format (PyExc_ValueError , "Another profiling tool is already active" );
785
- Py_DECREF (monitoring );
786
- return NULL ;
788
+ goto error ;
787
789
}
790
+ Py_DECREF (check );
788
791
789
792
for (int i = 0 ; callback_table [i ].callback_method ; i ++ ) {
793
+ int event = (1 << callback_table [i ].event );
790
794
PyObject * callback = PyObject_GetAttrString ((PyObject * )self , callback_table [i ].callback_method );
791
795
if (!callback ) {
792
- Py_DECREF (monitoring );
793
- return NULL ;
796
+ goto error ;
794
797
}
795
- Py_XDECREF ( PyObject_CallMethod (monitoring , "register_callback" , "iiO" , self -> tool_id ,
796
- ( 1 << callback_table [ i ]. event ) ,
797
- callback ) );
798
+ PyObject * register_result = PyObject_CallMethod (monitoring , "register_callback" ,
799
+ "iiO" , self -> tool_id ,
800
+ event , callback );
798
801
Py_DECREF (callback );
799
- all_events |= (1 << callback_table [i ].event );
802
+ if (register_result == NULL ) {
803
+ goto error ;
804
+ }
805
+ Py_DECREF (register_result );
806
+ all_events |= event ;
800
807
}
801
808
802
- if (!PyObject_CallMethod (monitoring , "set_events" , "ii" , self -> tool_id , all_events )) {
803
- Py_DECREF (monitoring );
804
- return NULL ;
809
+ PyObject * event_result = PyObject_CallMethod (monitoring , "set_events" , "ii" ,
810
+ self -> tool_id , all_events );
811
+ if (event_result == NULL ) {
812
+ goto error ;
805
813
}
806
814
815
+ Py_DECREF (event_result );
807
816
Py_DECREF (monitoring );
808
817
809
818
self -> flags |= POF_ENABLED ;
810
819
Py_RETURN_NONE ;
820
+
821
+ error :
822
+ Py_DECREF (monitoring );
823
+ return NULL ;
811
824
}
812
825
813
826
static void
0 commit comments