Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leak in makemon.c #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ashamedbit
Copy link

@ashamedbit ashamedbit commented Feb 28, 2024

Hi,
I am anew contributor that loves playing this game! So I thought I would also help contribute to this amazing game :)

This PR fixes leak in #505 .

=================================================================
==13717==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 128 byte(s) in 1 object(s) allocated from:
#0 0x7f381436a808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
https://github.com/elunna/hackem/issues/1 0x55f57f49e685 in alloc /home/user/hackem/src/alloc.c:46
https://github.com/elunna/hackem/issues/2 0x55f57fabde5e in mksobj /home/user/hackem/src/mkobj.c:852
https://github.com/elunna/hackem/issues/3 0x55f57f8bfcab in mongets /home/user/hackem/src/makemon.c:4176
https://github.com/elunna/hackem/issues/4 0x55f57f8a2b43 in m_initweap /home/user/hackem/src/makemon.c:1800
https://github.com/elunna/hackem/issues/5 0x55f57f8a4e72 in setup_mon_inventory /home/user/hackem/src/makemon.c:2304
https://github.com/elunna/hackem/issues/6 0x55f57f8b2d70 in makemon /home/user/hackem/src/makemon.c:3578
https://github.com/elunna/hackem/issues/7 0x55f57feba0ff in create_monster /home/user/hackem/src/sp_lev.c:1715
https://github.com/elunna/hackem/issues/8 0x55f57fec84f1 in spo_monster /home/user/hackem/src/sp_lev.c:3279
https://github.com/elunna/hackem/issues/9 0x55f57feddeda in sp_level_coder /home/user/hackem/src/sp_lev.c:5665
https://github.com/elunna/hackem/issues/10 0x55f57fee2f06 in load_special /home/user/hackem/src/sp_lev.c:6346
https://github.com/elunna/hackem/issues/11 0x55f57fab1241 in makemaz /home/user/hackem/src/mkmaze.c:1027
https://github.com/elunna/hackem/issues/12 0x55f57fa9a1c9 in makelevel /home/user/hackem/src/mklev.c:934
https://github.com/elunna/hackem/issues/13 0x55f57fa9d79a in mklev /home/user/hackem/src/mklev.c:1388
https://github.com/elunna/hackem/issues/14 0x55f57f65647e in goto_level /home/user/hackem/src/do.c:1926
https://github.com/elunna/hackem/issues/15 0x55f57f749350 in next_level /home/user/hackem/src/dungeon.c:1176
https://github.com/elunna/hackem/issues/16 0x55f57f6534f7 in dodown /home/user/hackem/src/do.c:1511
https://github.com/elunna/hackem/issues/17 0x55f57f5a7491 in rhack /home/user/hackem/src/cmd.c:5800
https://github.com/elunna/hackem/issues/18 0x55f57f49a774 in moveloop /home/user/hackem/src/allmain.c:859
https://github.com/elunna/hackem/issues/19 0x55f5801a1b15 in main ../sys/unix/unixmain.c:353
https://github.com/elunna/hackem/issues/20 0x7f3814036082 in __libc_start_main ../csu/libc-start.c:308

SUMMARY: AddressSanitizer: 128 byte(s) leaked in 1 allocation(s).

The leak occurs in function mongets. Here otmp is allocated by mksobj but not freed if mpickobj fails to free otmp.

The patch frees otmp in the case that mpickobj fails.

Let me know if you found the patch useful or if any modifications are needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant