From 9d432ebd4d8cae684fd8036ac10fcf3804579d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D1=80=D1=83=D1=84=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80?= Date: Mon, 8 Jan 2024 19:11:50 +0300 Subject: [PATCH] Fix memory leaks --- ta-lib-rt/c/src/ta_func/ta_ATR.c | 12 +++++------- ta-lib-rt/c/src/ta_func/ta_MA.c | 8 +++----- .../tools/ta_regtest/ta_test_func/test_candlestick.c | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ta-lib-rt/c/src/ta_func/ta_ATR.c b/ta-lib-rt/c/src/ta_func/ta_ATR.c index db006c65e..d94e087f3 100644 --- a/ta-lib-rt/c/src/ta_func/ta_ATR.c +++ b/ta-lib-rt/c/src/ta_func/ta_ATR.c @@ -581,18 +581,16 @@ double tempReal, tempATR; /**** END GENCODE SECTION 9 - DO NOT DELETE THIS LINE ****/ { /* insert local variable here */ - if( STATE_P.optInTimePeriod <= 1 ) - { - /* No smoothing needed. Just do a TRANGE. */ - return FUNCTION_CALL_STATE_FREE(TRANGE)( (struct TA_TRANGE_State**) &STATE_P.StateTRANGE); - } TA_RetCode retCode; retCode = FUNCTION_CALL_STATE_FREE(TRANGE)( (struct TA_TRANGE_State**) &STATE_P.StateTRANGE ); if (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) return retCode; - else retCode = FUNCTION_CALL_STATE_FREE(SMA)( (struct TA_SMA_State**) &STATE_P.StateSMA ); - if (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) return retCode; + + if( STATE_P.optInTimePeriod > 1 ) { + retCode = FUNCTION_CALL_STATE_FREE(SMA)( (struct TA_SMA_State**) &STATE_P.StateSMA ); + if (retCode != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) return retCode; + } /**** START GENCODE SECTION 10 - DO NOT DELETE THIS LINE ****/ /* Generated */ diff --git a/ta-lib-rt/c/src/ta_func/ta_MA.c b/ta-lib-rt/c/src/ta_func/ta_MA.c index f0e7067db..7e046464a 100644 --- a/ta-lib-rt/c/src/ta_func/ta_MA.c +++ b/ta-lib-rt/c/src/ta_func/ta_MA.c @@ -709,12 +709,10 @@ if( STATE_P.optInTimePeriod != 1 ) default: retValue = ENUM_VALUE(RetCode,TA_BAD_PARAM, BadParam); } -} else { - return ENUM_VALUE(RetCode,TA_SUCCESS,Success); -} -if (retValue != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) - return retValue; + if (retValue != ENUM_VALUE(RetCode,TA_SUCCESS,Success)) + return retValue; +} /**** START GENCODE SECTION 10 - DO NOT DELETE THIS LINE ****/ /* Generated */ diff --git a/ta-lib-rt/c/src/tools/ta_regtest/ta_test_func/test_candlestick.c b/ta-lib-rt/c/src/tools/ta_regtest/ta_test_func/test_candlestick.c index f5b9395c5..7e36a74d4 100644 --- a/ta-lib-rt/c/src/tools/ta_regtest/ta_test_func/test_candlestick.c +++ b/ta-lib-rt/c/src/tools/ta_regtest/ta_test_func/test_candlestick.c @@ -756,7 +756,7 @@ static ErrorNumber do_test_state( const TA_History *history, { TA_RangeTestParam testParam; ErrorNumber errNb; - TA_RetCode retCode; + TA_RetCode retCode = TA_SUCCESS; (void)test;