From 5ec839727a8720640a354e3b4b78cf099ea8cc4d Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 14 Oct 2026 01:25:49 -0500 Subject: [PATCH] Fix memory leak if duplicate RTSP options are inserted --- src/RtspParser.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/RtspParser.c b/src/RtspParser.c index 208d853..3e8d664 100644 --- a/src/RtspParser.c +++ b/src/RtspParser.c @@ -292,9 +292,22 @@ void insertOption(POPTION_ITEM* optionsHead, POPTION_ITEM opt) { // Traverse the list and insert the new option at the end while (current != NULL) { + // Check for self-insertion + if (current == opt) { + LC_ASSERT(current != opt); + return; + } + // Check for duplicate option; if so, replace the option currently there if (!strcmp(current->option, opt->option)) { + if (current->flags & FLAG_ALLOCATED_OPTION_FIELDS) { + free(current->option); + free(current->content); + } + current->option = opt->option; current->content = opt->content; + current->flags = opt->flags; + free(opt); return; } if (current->next == NULL) {