Skip to content

Commit db0ba84

Browse files
Janne Huttunenacmel
authored andcommitted
perf script python: Fix dict reference counting
The dictionaries are attached to the parameter tuple that steals the references and takes care of releasing them when appropriate. The code should not decrement the reference counts explicitly. E.g. if libpython has been built with reference debugging enabled, the superfluous DECREFs will trigger this error when running perf script: Fatal Python error: Objects/tupleobject.c:238 object at 0x7f10f2041b40 has negative ref count -1 Aborted (core dumped) If the reference debugging is not enabled, the superfluous DECREFs might cause the dict objects to be silently released while they are still in use. This may trigger various other assertions or just cause perf crashes and/or weird and unexpected data changes in the stored Python objects. Signed-off-by: Janne Huttunen <[email protected]> Acked-by: Jiri Olsa <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jaroslav Skarvada <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent c818cc0 commit db0ba84

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

tools/perf/util/scripting-engines/trace-event-python.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -908,14 +908,11 @@ static void python_process_tracepoint(struct perf_sample *sample,
908908
if (_PyTuple_Resize(&t, n) == -1)
909909
Py_FatalError("error resizing Python tuple");
910910

911-
if (!dict) {
911+
if (!dict)
912912
call_object(handler, t, handler_name);
913-
} else {
913+
else
914914
call_object(handler, t, default_handler_name);
915-
Py_DECREF(dict);
916-
}
917915

918-
Py_XDECREF(all_entries_dict);
919916
Py_DECREF(t);
920917
}
921918

@@ -1235,7 +1232,6 @@ static void python_process_general_event(struct perf_sample *sample,
12351232

12361233
call_object(handler, t, handler_name);
12371234

1238-
Py_DECREF(dict);
12391235
Py_DECREF(t);
12401236
}
12411237

0 commit comments

Comments
 (0)