Skip to contentSkip to conversation

libtraceevent: Fix double free in event_read_fields()

PATCH New Shang XiaoJing 1 participant 1 message Oct 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtraceevent: Fix double free in event_read_fields()

There is a double free in event_read_fields(). After calling free_token() to free the token, if append() failed, then goto fail, which will call free_token() again. Triggered by compiling with perf and run "perf sched record". Fix the double free by goto fail_expect instead of fail while append() failed, which won't call redundant free_token().

BUG: double free

free(): double free detected in tcache 2
Aborted

Fixes ae6c0749ca74 ("tools lib traceevent: Handle realloc() failure path")
---
 src/event-parse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/event-parse.c +1 -1
index a0d7da5..d842f9d 100644
@@ -1779,7 +1779,7 @@ static int event_read_fields(struct tep_event *event, struct tep_format_field **
 			ret = append(&brackets, "", "]");
 			if (ret < 0) {
 				free(brackets);
-				goto fail;
+				goto fail_expect;
 			}
 
 			/* add brackets to type */
Signature · 1 line
2.17.1