From cd3a5155a8f1999d5870d31ad0be9bfb0a309d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Ma=C5=82ecki?= Date: Fri, 24 Jul 2020 18:22:50 +0200 Subject: [PATCH] [core] Fixed wrong filling group data --- srtcore/core.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/srtcore/core.cpp b/srtcore/core.cpp index 6eaf11fb6..b02d73150 100644 --- a/srtcore/core.cpp +++ b/srtcore/core.cpp @@ -12640,21 +12640,34 @@ void CUDTGroup::fillGroupData( const SRT_MSGCTRL& in // MSGCTRL read from the data-providing socket ) { + // Preserve the data that will be overwritten by assignment SRT_SOCKGROUPDATA* grpdata = w_out.grpdata; + size_t grpdata_size = w_out.grpdata_size; w_out = in; // NOTE: This will write NULL to grpdata and 0 to grpdata_size! + w_out.grpdata = NULL; // Make sure it's done, for any case + w_out.grpdata_size = 0; + // User did not wish to read the group data at all. if (!grpdata) { - w_out.grpdata = NULL; - w_out.grpdata_size = 0; return; } - int st = getGroupData((grpdata), (&w_out.grpdata_size)); - // On error, rewrite NULL. - w_out.grpdata = st != SRT_ERROR ? grpdata : NULL; + int st = getGroupData((grpdata), (&grpdata_size)); + + // Always write back the size, no matter if the data were filled. + w_out.grpdata_size = grpdata_size; + + if (st == SRT_ERROR) + { + // Keep NULL in grpdata + return; + } + + // Write back original data + w_out.grpdata = grpdata; } struct FLookupSocketWithEvent