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 memory leak in main view #931

Merged
merged 1 commit into from Jun 1, 2019
Merged

Conversation

stevenyvr987
Copy link
Contributor

@stevenyvr987 stevenyvr987 commented Jun 1, 2019

When the main_done() is called, done_graph() is called, which calls free(graph), where graph is a pointer to a struct graph. struct graph points to a hash table colors.id_map, which should be freed before free(graph) is called.

The memory leak can be induced in the main view by defining the keybinding on the prompt line :bind main t !t true, where true is essentially a shell no-op. Pressing t in the main view and then quitting will get a LeakSanitizer report of a direct leak. The leak happens for each t command so that the amount leaked is proportional to the number of times main_done() is called.

Direct leak of 112 byte(s) in 1 object(s) allocated from:
0x7effa34b7d38 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xded38)
0x5639427502ac in htab_create_typed_alloc compat/hashtab.c:358
0x563942750421 in htab_create_alloc compat/hashtab.c:286
0x56394274ec1c in colors_init src/graph-v2.c:219
0x56394274ec1c in get_color src/graph-v2.c:231
0x56394274ec1c in graph_generate_symbols src/graph-v2.c:727
0x56394274ec1c in graph_render_parents src/graph-v2.c:748
0x56394274533f in main_read src/main.c:461
0x5639427213bb in update_view src/view.c:611
0x56394271961b in update_views src/display.c:757
0x56394271961b in get_input src/display.c:802
0x56394270f856 in prompt_input src/prompt.c:55
0x5639426ec9ad in read_key_combo src/tig.c:745
0x5639426e9976 in main src/tig.c:855
0x7effa2967b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

When the main_done() is called, done_graph() is called, which calls free(graph), where graph is a pointer to a struct graph.

struct graph points to a hash table colors.id_map, which should be freed before the call to free(graph).
@koutcher koutcher merged commit 9ca7710 into jonas:master Jun 1, 2019
koutcher added a commit that referenced this pull request Nov 25, 2019
As reported by Maxim Zhukov, the commit 9ca7710 ("Fix memory leak in
main view (#931)", 01-06-2019) causes a SIGSEGV when holding the key
'Stage/Unstage current line' in stage view.

Add a check to avoid null pointer dereference.

Fixes #971
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.

None yet

2 participants