]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
cmd: Fix memory leak in cbuf. Use a dedicated mempool instead of the temp one
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Sep 2020 13:49:33 +0000 (13:49 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 23 Sep 2020 13:49:33 +0000 (13:49 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12937 d7cf8633-e32d-0410-b094-e92efae38249

cmd.c

diff --git a/cmd.c b/cmd.c
index 29eef47b443ea40389d77f2985c6b32426e53fd6..34a5da43e4ee0ebd2fe3ffdaa40678966550e467 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -41,6 +41,7 @@ static cmd_iter_t cmd_iter_all[] = {
        {NULL},
 };
 
+mempool_t *cbuf_mempool;
 
 // we only run the +whatever commandline arguments once
 qbool host_stuffcmdsrun = false;
@@ -192,7 +193,7 @@ static cmd_input_t *Cbuf_LinkGet(cmd_buf_t *cbuf, cmd_input_t *existing)
 
 static cmd_input_t *Cmd_AllocInputNode(void)
 {
-       cmd_input_t *node = (cmd_input_t *)Z_Malloc(sizeof(cmd_input_t));
+       cmd_input_t *node = (cmd_input_t *)Mem_Alloc(cbuf_mempool, sizeof(cmd_input_t));
        node->list.prev = node->list.next = &node->list;
        node->size = node->length = node->pending = 0;
        return node;
@@ -291,7 +292,7 @@ static size_t Cmd_ParseInput (cmd_input_t **output, char **input)
 
                if((*output)->size < (*output)->length + 1)
                {
-                       (*output)->text = (char *)Mem_Realloc(tempmempool, (*output)->text, (*output)->size + cmdsize + 1);
+                       (*output)->text = (char *)Mem_Realloc(cbuf_mempool, (*output)->text, (*output)->length + 1);
                        (*output)->size = (*output)->length + 1;
                }
 
@@ -1604,7 +1605,9 @@ Cmd_Init
 void Cmd_Init(void)
 {
        cmd_iter_t *cmd_iter;
-       cmd_buf_t *cbuf = (cmd_buf_t *)Z_Malloc(sizeof(cmd_buf_t));
+       cmd_buf_t *cbuf;
+       cbuf_mempool = Mem_AllocPool("Command buffer", 0, NULL);
+       cbuf = (cmd_buf_t *)Mem_Alloc(cbuf_mempool, sizeof(cmd_buf_t));
        cbuf->maxsize = 655360;
        cbuf->lock = Thread_CreateMutex();
        cbuf->wait = false;