lkml.org 
[lkml]   [2014]   [Jul]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/3] perf script: Add missing calls to Py_DECREF
Em Wed, Jul 09, 2014 at 04:16:31PM +0200, Joseph Schuchart escreveu:
>
> perf script: Add missing calls to Py_DECREF for return values

I'm applying this one, but please next time write a few lines explaining
what happens without the patch and thus what it fixes, i.e. why is a
Py_DECREF needed in this case?

- Arnaldo

> Signed-off-by: Joseph Schuchart <joseph.schuchart@tu-dresden.de>
> ---
> tools/perf/util/scripting-engines/trace-event-python.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index e55b65a..b6c1a69 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -50,10 +50,14 @@ static int zero_flag_atom;
>
> static PyObject *main_module, *main_dict;
>
> +static void handler_call_die(const char *handler_name) NORETURN;
> static void handler_call_die(const char *handler_name)
> {
> PyErr_Print();
> Py_FatalError("problem in Python trace event handler");
> + // Py_FatalError does not return
> + // but we have to make the compiler happy
> + abort();
> }
>
> /*
> @@ -97,6 +101,7 @@ static void define_value(enum print_arg_type field_type,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> }
>
> Py_DECREF(t);
> @@ -143,6 +148,7 @@ static void define_field(enum print_arg_type field_type,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> }
>
> Py_DECREF(t);
> @@ -361,6 +367,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> } else {
> handler = PyDict_GetItemString(main_dict, "trace_unhandled");
> if (handler && PyCallable_Check(handler)) {
> @@ -368,6 +375,7 @@ static void python_process_tracepoint(struct perf_sample *sample,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die("trace_unhandled");
> + Py_DECREF(retval);
> }
> Py_DECREF(dict);
> }
> @@ -427,6 +435,7 @@ static void python_process_general_event(struct perf_sample *sample,
> retval = PyObject_CallObject(handler, t);
> if (retval == NULL)
> handler_call_die(handler_name);
> + Py_DECREF(retval);
> exit:
> Py_DECREF(dict);
> Py_DECREF(t);
> @@ -548,8 +557,7 @@ static int python_stop_script(void)
> retval = PyObject_CallObject(handler, NULL);
> if (retval == NULL)
> handler_call_die("trace_end");
> - else
> - Py_DECREF(retval);
> + Py_DECREF(retval);
> out:
> Py_XDECREF(main_dict);
> Py_XDECREF(main_module);
> --
> 1.8.1.2
>
>




\
 
 \ /
  Last update: 2014-07-10 01:21    [W:0.171 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site