fix(bitscrambler): clean up loopback create failures

Clear the returned handle on loopback creation failure and route
initialized objects through bitscrambler_free so channel ownership and
extra cleanup state cannot leak after partial setup errors. Add a
regression test for the failed create path.
This commit is contained in:
morris
2026-08-03 10:18:38 +08:00
parent 0c1e6bd965
commit db76b4cb1b
2 changed files with 23 additions and 5 deletions
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdio.h>
#include <stdint.h>
#include "sdkconfig.h"
#include "unity.h"
#include "unity_test_utils.h"
@@ -59,6 +60,19 @@ TEST_CASE("Timeout on stuck program", "[bs]")
free(data_out);
}
TEST_CASE("Loopback create failure clears handle and releases channels", "[bs]")
{
bitscrambler_handle_t failed_bs = (bitscrambler_handle_t)0x1;
esp_err_t err = bitscrambler_loopback_create(&failed_bs, SOC_BITSCRAMBLER_ATTACH_GPSPI2, SIZE_MAX / 2);
TEST_ASSERT_NOT_EQUAL(ESP_OK, err);
TEST_ASSERT_NULL(failed_bs);
bitscrambler_handle_t bs = NULL;
TEST_ESP_OK(bitscrambler_loopback_create(&bs, SOC_BITSCRAMBLER_ATTACH_GPSPI2, 4096));
bitscrambler_free(bs);
}
TEST_CASE("BitScrambler with EOF counted on upstream", "[bs]")
{
const size_t len = 32;