Skip to content

Commit

Permalink
sp_lvl: fix memory leak on lspo_region
Browse files Browse the repository at this point in the history
If tutorial is entered, we get following leak on exit:

=================================================================
==81358==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 96 byte(s) in 3 object(s) allocated from:
    #0 0x7f6996edefdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x5601c255bcbb in alloc /home/miku/src/NetHack/src/alloc.c:71

Indirect leak of 5064 byte(s) in 3 object(s) allocated from:
    #0 0x7f6996edefdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
        #1 0x5601c255be1e in alloc /home/miku/src/NetHack/src/alloc.c:71
	    #2 0x5601c255be1e in dupstr /home/miku/src/NetHack/src/alloc.c:236

SUMMARY: AddressSanitizer: 5160 byte(s) leaked in 6 allocation(s).

Fix this by freeing the cloned selection before returning.
  • Loading branch information
mkuoppal authored and paxed committed Dec 17, 2023
1 parent a2aa4ed commit e6c4838
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/sp_lev.c
Original file line number Diff line number Diff line change
Expand Up @@ -6191,6 +6191,8 @@ lspo_region(lua_State *L)
selection_do_grow(sel, W_ANY);
selection_iterate(sel, sel_set_lit, (genericptr_t) &rlit);

selection_free(sel, TRUE);

/* TODO: skip the rest of this function? */
return 0;
} else {
Expand Down

0 comments on commit e6c4838

Please sign in to comment.