Re: [PATCH]Perf: Return error code for perf_session__new function on failure
From: Jiri Olsa
Date: Thu Aug 15 2019 - 08:51:07 EST
On Wed, Aug 14, 2019 at 03:02:18PM +0530, Mamatha Inamdar wrote:
SNIP
> #ifdef HAVE_ZSTD_SUPPORT
> static int perf_session__process_compressed_event(struct perf_session *session,
> @@ -181,6 +182,7 @@ static int ordered_events__deliver_event(struct ordered_events *oe,
> struct perf_session *perf_session__new(struct perf_data *data,
> bool repipe, struct perf_tool *tool)
> {
> + int ret = 0;
hum, should ret be initialized to -ENOMEM instead?
jirka
> struct perf_session *session = zalloc(sizeof(*session));
>
> if (!session)
> @@ -195,13 +197,15 @@ struct perf_session *perf_session__new(struct perf_data *data,
>
> perf_env__init(&session->header.env);
> if (data) {
> - if (perf_data__open(data))
> + ret = perf_data__open(data);
> + if (ret < 0)
> goto out_delete;
>
> session->data = data;
>
> if (perf_data__is_read(data)) {
> - if (perf_session__open(session) < 0)
> + ret = perf_session__open(session);
> + if (ret < 0)
> goto out_delete;
>
> /*
> @@ -216,7 +220,8 @@ struct perf_session *perf_session__new(struct perf_data *data,
> perf_evlist__init_trace_event_sample_raw(session->evlist);
>
> /* Open the directory data. */
> - if (data->is_dir && perf_data__open_dir(data))
> + ret = data->is_dir && perf_data__open_dir(data);
> + if (ret)
> goto out_delete;
> }
> } else {
> @@ -250,7 +255,7 @@ struct perf_session *perf_session__new(struct perf_data *data,
> out_delete:
> perf_session__delete(session);
> out:
> - return NULL;
> + return ERR_PTR(ret);
> }
>
> static void perf_session__delete_threads(struct perf_session *session)
>