engine: fix memory leak in netchan

frag_message_buf wasn't always freed alongside with fragbuf_t
instead of ensuring frag_message_buf being freed, I turned it into
a flexible array member
This commit is contained in:
Alibek Omarov
2024-08-03 08:40:31 +03:00
parent e686b1410d
commit d6e77e531d
2 changed files with 3 additions and 5 deletions

View File

@@ -379,7 +379,6 @@ static void Netchan_ClearFragbufs( fragbuf_t **ppbuf )
while( buf )
{
n = buf->next;
Mem_Free( buf->frag_message_buf );
Mem_Free( buf );
buf = n;
}
@@ -505,8 +504,7 @@ static fragbuf_t *Netchan_AllocFragbuf( int fragment_size )
{
fragbuf_t *buf;
buf = (fragbuf_t *)Mem_Calloc( net_mempool, sizeof( fragbuf_t ));
buf->frag_message_buf = (byte *)Mem_Calloc( net_mempool, fragment_size );
buf = (fragbuf_t *)Mem_Calloc( net_mempool, sizeof( fragbuf_t ) + ( fragment_size - 1 ) );
MSG_Init( &buf->frag_message, "Frag Message", buf->frag_message_buf, fragment_size );
return buf;
@@ -520,7 +518,7 @@ Netchan_AddFragbufToTail
*/
static void Netchan_AddFragbufToTail( fragbufwaiting_t *wait, fragbuf_t *buf )
{
fragbuf_t *p;
fragbuf_t *p;
buf->next = NULL;
wait->fragbufcount++;

View File

@@ -184,13 +184,13 @@ typedef struct fragbuf_s
struct fragbuf_s *next; // next buffer in chain
int bufferid; // id of this buffer
sizebuf_t frag_message; // message buffer where raw data is stored
byte *frag_message_buf; // the actual data sits here
qboolean isfile; // is this a file buffer?
qboolean isbuffer; // is this file buffer from memory ( custom decal, etc. ).
qboolean iscompressed; // is compressed file, we should using filename.ztmp
char filename[MAX_OSPATH]; // name of the file to save out on remote host
int foffset; // offset in file from which to read data
int size; // size of data to read at that offset
byte frag_message_buf[1]; // the actual data sits here (flexible)
} fragbuf_t;
// Waiting list of fragbuf chains