From 46f431a4d755cfc4474dac93aa3f96ac226d16c8 Mon Sep 17 00:00:00 2001 From: Jon Foster Date: Fri, 24 Dec 2021 10:10:34 -0800 Subject: [PATCH] Firm up memory leak changes The solution works well in my test cases. I removed the rem'd out code and updated the change remarks. Also bumped the version number. --- bwb_exp.c | 29 +++-------------------------- bwb_var.c | 1 - bwbasic.c | 2 +- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/bwb_exp.c b/bwb_exp.c index 29bc8d3..d044c21 100644 --- a/bwb_exp.c +++ b/bwb_exp.c @@ -2702,31 +2702,11 @@ buff_read_function (char *buffer, int *position, VariantType * X) { /* STRING */ var_make (argn, StringTypeCode); - /* CM-20211223 this is double allocating, squashing the - pointer from the calloc() within var_make(). The RAM! It - be leakin'! */ - /*if ((argn->Value.String = - (StringType *) calloc (1, sizeof (StringType))) == NULL) - { - WARN_OUT_OF_MEMORY; - return RESULT_ERROR; - }*/ + /* CM-20211223 plug RAM leak. var_make() allocs RAM. */ PARAM_LENGTH = T.Length; - /* CM-20211223 either we keep the buffer instead of making a - new one or we need to free it. See RELEASE_VARIANT below. - I'm unremm'ing PARAM_BUFFER and leaving RELEASE_VARIANT - disabled. */ + /* CM-20211223 Fix the RAM leak. We keep the buffer instead + of making a new one and copying it. This is faster. */ PARAM_BUFFER = T.Buffer; - /*if ((PARAM_BUFFER = - (char *) calloc (T.Length + 1 /* NulChar *//* , - sizeof (char))) == NULL) - { - WARN_OUT_OF_MEMORY; - return RESULT_ERROR; - } - bwb_memcpy (PARAM_BUFFER, T.Buffer, T.Length); - PARAM_BUFFER[PARAM_LENGTH] = NulChar;*/ - /* add type to ParameterTypes */ if (ParameterCount < MAX_FARGS) { ParameterTypes |= (1 << ParameterCount); @@ -2743,9 +2723,6 @@ buff_read_function (char *buffer, int *position, VariantType * X) { ParameterCount++; } - /* CM-20211223 see comment dated the same just above. I chose to - keep the buffer... wondering why these had been rem'd out... */ - /* RELEASE_VARIANT( &T ); */ } while (buff_skip_seperator (buffer, &p)); diff --git a/bwb_var.c b/bwb_var.c index 657957a..0ef6706 100644 --- a/bwb_var.c +++ b/bwb_var.c @@ -348,7 +348,6 @@ var_free (VariableType * variable) variable->Value.String[j].length = 0; } free (variable->Value.String); - ; variable->Value.String = NULL; } } diff --git a/bwbasic.c b/bwbasic.c index 2f4ec13..c0a1547 100644 --- a/bwbasic.c +++ b/bwbasic.c @@ -83,7 +83,7 @@ static char *Banner[] = { " ## ## ## ## ## ## ## ## ##", " ######## ## ## ###### #### ###### ", " ", - "Bywater BASIC Interpreter, version 3.20f ", + "Bywater BASIC Interpreter, version 3.20g ", "Copyright (c) 1993, Ted A. Campbell ", "Copyright (c) 1995-1997 , Jon B. Volkoff ", "Copyright (c) 2014-2017 , Howard Wulf, AF5NE ",