tools lib traceevent: Small fixes on error handling path
cover tools lib traceevent: Small fixes on error handling path
Hi,
During a review on Arnaldo's libtraceevent cleanup patches, I've found some possible memory leaks and a dangling pointer problem. Please take a look at them too.
Thanks,
Namhyung
Namhyung Kim (4):
tools lib traceevent: Fix error path on process_array()
tools lib traceevent: Make sure that arg->op.right is set properly tools lib traceevent: Free field if an error occurs on process_fields tools lib traceevent: Free field if an error occurs on process_flags/symbols
tools/lib/traceevent/event-parse.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
Signature · 1 line
1.7.11.4
PATCH 1/4 tools lib traceevent: Fix error path on process_array()
From: Namhyung Kim <[email protected]>
free_token() under out_free should be called with 'token' and no need to set *tok to NULL since it's set already.
--- tools/lib/traceevent/event-parse.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/lib/traceevent/event-parse.c +1 -2
@@ -1636,8 +1636,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)return type; out_free: -free_token (*tok); - *tok =NULL ; +free_token (token);free_arg (arg);return EVENT_ERROR ; }
Signature · 1 line
1.7.11.4
[tip:perf/core] tools lib traceevent: Fix error path on process_array()
Commit-ID: 1bce6e0fec28434fd66de585773a14bf4d2c3715 Gitweb: http://git.kernel.org/tip/1bce6e0fec28434fd66de585773a14bf4d2c3715 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 19 Sep 2012 15:58:41 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 24 Sep 2012 12:00:15 -0300
tools lib traceevent: Fix error path on process_array()
free_token() under out_free should be called with 'token' and no need to set *tok to NULL since it's set already.
--- tools/lib/traceevent/event-parse.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
tools/lib/traceevent/event-parse.c +1 -2
@@ -1595,8 +1595,7 @@ process_array(struct event_format *event, struct print_arg *top, char **tok)return type; out_free: -free_token (*tok); - *tok =NULL ; +free_token (token);free_arg (arg);return EVENT_ERROR ; }
PATCH 2/4 tools lib traceevent: Make sure that arg->op.right is set properly
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
When process_op failed, @arg will be freed on a caller with type of PRINT_OP. Thus free_arg() will try to free ->op.right field which can have stale value if something bad happens in the middle.
--- tools/lib/traceevent/event-parse.c | 3 +++ 1 file changed, 3 insertions(+)
tools/lib/traceevent/event-parse.c +3 -0
@@ -1772,6 +1772,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) arg->op.left = left; arg->op.prio =0 ; +/* it will set arg->op.right */ type =process_cond (event, arg, tok); } else if (strcmp(token, ">>") == 0 ||
@@ -1802,6 +1803,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) arg->type =PRINT_OP ; arg->op.op = token; arg->op.left = left; + arg->op.right =NULL ;if (set_op_prio (arg) ==-1 ) { event->flags |=EVENT_FL_FAILED ;
@@ -1859,6 +1861,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) arg->op.prio =0 ; +/* it will set arg->op.right */ type =process_array (event, arg, tok); }else {
Signature · 1 line
1.7.11.4
[tip:perf/core] tools lib traceevent: Make sure that arg->op. right is set properly
Commit-ID: 41e51a289b3ca83e08395213f4488c9c7c6b2e29 Gitweb: http://git.kernel.org/tip/41e51a289b3ca83e08395213f4488c9c7c6b2e29 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 19 Sep 2012 15:58:42 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 24 Sep 2012 12:01:21 -0300
tools lib traceevent: Make sure that arg->op.right is set properly
When process_op failed, @arg will be freed on a caller with type of PRINT_OP. Thus free_arg() will try to free ->op.right field which can have stale value if something bad happens in the middle.
--- tools/lib/traceevent/event-parse.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
tools/lib/traceevent/event-parse.c +3 -0
@@ -1719,6 +1719,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) arg->op.left = left; arg->op.prio =0 ; +/* it will set arg->op.right */ type =process_cond (event, arg, tok); } else if (strcmp(token, ">>") == 0 ||
@@ -1745,6 +1746,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) arg->type =PRINT_OP ; arg->op.op = token; arg->op.left = left; + arg->op.right =NULL ;if (set_op_prio (arg) ==-1 ) { event->flags |=EVENT_FL_FAILED ;
@@ -1792,6 +1794,7 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok) arg->op.prio =0 ; +/* it will set arg->op.right */ type =process_array (event, arg, tok); }else {
PATCH 3/4 tools lib traceevent: Free field if an error occurs on process_fields
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
The field should be freed on error paths.
--- tools/lib/traceevent/event-parse.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
tools/lib/traceevent/event-parse.c +7 -5
@@ -2262,10 +2262,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** value =arg_eval (arg);if (value ==NULL ) - goto out_free; + goto out_free_field; field->value =strdup (value);if (field->value ==NULL ) - goto out_free; + goto out_free_field;free_arg (arg); arg =alloc_arg ();
@@ -2275,14 +2275,14 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **free_token (token); type =process_arg (event, arg, &token);if (test_type_token (type, token,EVENT_OP ,"}" )) - goto out_free; + goto out_free_field; value =arg_eval (arg);if (value ==NULL ) - goto out_free; + goto out_free_field; field->str =strdup (value);if (field->str ==NULL ) - goto out_free; + goto out_free_field;free_arg (arg); arg =NULL ;
@@ -2296,6 +2296,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** *tok = token;return type; +out_free_field: +free_flag_sym (field); out_free:free_arg (arg);free_token (token);
Signature · 1 line
1.7.11.4
[tip:perf/core] tools lib traceevent: Free field if an error occurs on process_fields
Commit-ID: f8c49d2645e5028e48ba15ec72728be121eddf95 Gitweb: http://git.kernel.org/tip/f8c49d2645e5028e48ba15ec72728be121eddf95 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 19 Sep 2012 15:58:43 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 24 Sep 2012 12:02:38 -0300
tools lib traceevent: Free field if an error occurs on process_fields
The field should be freed on error paths.
--- tools/lib/traceevent/event-parse.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
tools/lib/traceevent/event-parse.c +7 -5
@@ -2186,10 +2186,10 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** value =arg_eval (arg);if (value ==NULL ) - goto out_free; + goto out_free_field; field->value =strdup (value);if (field->value ==NULL ) - goto out_free; + goto out_free_field;free_arg (arg); arg =alloc_arg ();
@@ -2197,14 +2197,14 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **free_token (token); type =process_arg (event, arg, &token);if (test_type_token (type, token,EVENT_OP ,"}" )) - goto out_free; + goto out_free_field; value =arg_eval (arg);if (value ==NULL ) - goto out_free; + goto out_free_field; field->str =strdup (value);if (field->str ==NULL ) - goto out_free; + goto out_free_field;free_arg (arg); arg =NULL ;
@@ -2218,6 +2218,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char ** *tok = token;return type; +out_free_field: +free_flag_sym (field); out_free:free_arg (arg);free_token (token);
PATCH 4/4 tools lib traceevent: Free field if an error occurs on process_flags/symbols
In reply to Namhyung KimFrom: Namhyung Kim <[email protected]>
The field should be freed on error paths.
--- tools/lib/traceevent/event-parse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
tools/lib/traceevent/event-parse.c +8 -4
@@ -2329,7 +2329,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) type =process_op (event, field, &token);if (test_type_token (type, token,EVENT_DELIM ,"," )) - goto out_free; + goto out_free_field;free_token (token); arg->flags.field = field;
@@ -2351,7 +2351,9 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) type =read_token_item (tok);return type; - out_free: +out_free_field: +free_arg (field); +out_free:free_token (token); *tok =NULL ;return EVENT_ERROR ;
@@ -2375,7 +2377,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) type =process_arg (event, field, &token);if (test_type_token (type, token,EVENT_DELIM ,"," )) - goto out_free; + goto out_free_field; arg->symbol.field = field;
@@ -2387,7 +2389,9 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) type =read_token_item (tok);return type; - out_free: +out_free_field: +free_arg (field); +out_free:free_token (token); *tok =NULL ;return EVENT_ERROR ;
Signature · 1 line
1.7.11.4
[tip:perf/core] tools lib traceevent: Free field if an error occurs on process_flags/symbols
Commit-ID: 70d9304475730a63dd8da884abc7c76ee4772cd2 Gitweb: http://git.kernel.org/tip/70d9304475730a63dd8da884abc7c76ee4772cd2 Author: Namhyung Kim <[email protected]> AuthorDate: Wed, 19 Sep 2012 15:58:44 +0900 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Mon, 24 Sep 2012 12:03:18 -0300
tools lib traceevent: Free field if an error occurs on process_flags/symbols
The field should be freed on error paths.
--- tools/lib/traceevent/event-parse.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
tools/lib/traceevent/event-parse.c +8 -4
@@ -2247,7 +2247,7 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) type =process_op (event, field, &token);if (test_type_token (type, token,EVENT_DELIM ,"," )) - goto out_free; + goto out_free_field;free_token (token); arg->flags.field = field;
@@ -2269,7 +2269,9 @@ process_flags(struct event_format *event, struct print_arg *arg, char **tok) type =read_token_item (tok);return type; - out_free: +out_free_field: +free_arg (field); +out_free:free_token (token); *tok =NULL ;return EVENT_ERROR ;
@@ -2289,7 +2291,7 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) type =process_arg (event, field, &token);if (test_type_token (type, token,EVENT_DELIM ,"," )) - goto out_free; + goto out_free_field; arg->symbol.field = field;
@@ -2301,7 +2303,9 @@ process_symbols(struct event_format *event, struct print_arg *arg, char **tok) type =read_token_item (tok);return type; - out_free: +out_free_field: +free_arg (field); +out_free:free_token (token); *tok =NULL ;return EVENT_ERROR ;