diff mbox series

[38/38] trace-cmd lib: prevent a memory leak in tracecmd_tsync_proto_getall()

Message ID 20240605134054.2626953-39-jmarchan@redhat.com (mailing list archive)
State Accepted
Commit bce7ba61bbe30784901a1dff53172cefc2c103bf
Headers show
Series trace-cmd: fix misc issues found by static analysis | expand

Commit Message

Jerome Marchand June 5, 2024, 1:40 p.m. UTC
In tracecmd_tsync_proto_getall() if the allocation plist succeeded but
the allocation of plist->names didn't, the function just returns
without freeing plist. There is already a proper exit path that free
allocated ressource: just use it.

Fixes a RESOURCE_LEAK error (CWE-772)

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
---
 lib/trace-cmd/trace-timesync.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-timesync.c b/lib/trace-cmd/trace-timesync.c
index 75c27bab..6ee4e643 100644
--- a/lib/trace-cmd/trace-timesync.c
+++ b/lib/trace-cmd/trace-timesync.c
@@ -290,7 +290,7 @@  int tracecmd_tsync_proto_getall(struct tracecmd_tsync_protos **protos, const cha
 		goto error;
 	plist->names = calloc(count, sizeof(char *));
 	if (!plist->names)
-		return -1;
+		goto error;
 
 	for (i = 0, proto = tsync_proto_list; proto && i < (count - 1); proto = proto->next) {
 		if (!(proto->roles & role))