Skip to content

Commit b5546d3

Browse files
wjablon1kv2019i
authored andcommitted
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 8f98a4e commit b5546d3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/library_manager/llext_manager.c

Lines changed: 8 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_base_bss = (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,12 @@ static int llext_manager_unload_module(struct lib_manager_module *mctx)
330332
if (ret < 0)
331333
err = ret;
332334

335+
/* Mimic the logic from load_module where the .bss address is used for mapping
336+
* in case of e.g. lack of writable .data section
337+
*/
338+
if (!va_base_data)
339+
va_base_data = va_base_bss;
340+
333341
llext_manager_unmap_detached_sections(ldr, ext, LLEXT_MEM_DATA,
334342
va_base_data, data_size);
335343
ret = llext_manager_align_unmap(va_base_data, data_size);

0 commit comments

Comments
 (0)