Skip to content

Commit 6880376

Browse files
committed
nrf_compress: lzma: Workaround oddities with LZMA library
The LZMA library believes that free() should be called with an address of NULL, this is completely invalid, therefore ignore any attempt to free memory at this address Signed-off-by: Jamie McCrae <[email protected]>
1 parent 3ad9fcf commit 6880376

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

subsys/nrf_compress/src/lzma.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ static void *lzma_probs_alloc(ISzAllocPtr p, size_t size)
5656

5757
if (buffer == NULL) {
5858
LOG_ERR("Failed to allocate nRF compression library buffer (0x%x)", size);
59-
}
60-
6159
#ifdef CONFIG_NRF_COMPRESS_CLEANUP
62-
malloc_probs_size = size;
60+
} else {
61+
malloc_probs_size = size;
6362
#endif
63+
}
6464

6565
return buffer;
6666
#endif
@@ -84,9 +84,15 @@ static void lzma_probs_free(ISzAllocPtr p, void *address)
8484
{
8585
#if defined(CONFIG_NRF_COMPRESS_MEMORY_TYPE_MALLOC)
8686
#ifdef CONFIG_NRF_COMPRESS_CLEANUP
87-
like_mbedtls_zeroize(address, malloc_probs_size);
87+
if (address == NULL) {
88+
return;
89+
}
90+
91+
if (malloc_probs_size > 0) {
92+
like_mbedtls_zeroize(address, malloc_probs_size);
93+
malloc_probs_size = 0;
94+
}
8895

89-
malloc_probs_size = 0;
9096
#endif
9197
free(address);
9298
#else

0 commit comments

Comments
 (0)