Skip to content

Commit a1c0896

Browse files
committed
llext: fix memory leak in no-data case
If there is no .data section in a llext module, the base data address is replaced with the .bss address while loading the module. There is no a corresponding logic during module unloading. This causes a memory leak because FW attempts to free memory under a NULL address while the .bss memory remains allocated. This change adds the missing logic. Signed-off-by: Wojciech Jablonski <wojciech.jablonski@intel.com>
1 parent a32d983 commit a1c0896

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/library_manager/llext_manager.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ static int llext_manager_unload_module(struct lib_manager_module *mctx)
320320
/* Writable data (.data, .bss, etc.) */
321321
void __sparse_cache *va_base_data = (void __sparse_cache *)
322322
mctx->segment[LIB_MANAGER_DATA].addr;
323+
void __sparse_cache *va_bss_data = (void __sparse_cache *)
324+
mctx->segment[LIB_MANAGER_BSS].addr;
323325
size_t data_size = mctx->segment[LIB_MANAGER_DATA].size +
324326
mctx->segment[LIB_MANAGER_BSS].size;
325327
int err = 0, ret;
@@ -330,6 +332,8 @@ static int llext_manager_unload_module(struct lib_manager_module *mctx)
330332
if (ret < 0)
331333
err = ret;
332334

335+
va_base_data = va_base_data ? va_base_data : va_bss_data;
336+
333337
llext_manager_unmap_detached_sections(ldr, ext, LLEXT_MEM_DATA,
334338
va_base_data, data_size);
335339
ret = llext_manager_align_unmap(va_base_data, data_size);

0 commit comments

Comments
 (0)