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

There is a memory leak defect at line 1303 in the file /vim/src/dict.c. #14238

Closed
LuMingYinDetect opened this issue Mar 20, 2024 · 6 comments
Closed
Labels

Comments

@LuMingYinDetect
Copy link

Steps to reproduce

1.A pointer named d1 is defined at line 1272 in the file /vim/src/dict.c. This pointer is initialized to argvars[0].vval.v_dict at line 1276. Subsequently, this pointer is passed as an argument to the function dict_copy for copying at line 1291, and the copied memory space is assigned to the pointer d1, as shown in the diagram below:https://github.com/LuMingYinDetect/vim_defects/blob/main/vim_1.png
2.The dict_copy function actually allocates a new dynamic memory area and copies the content of the pointer to this memory area. At line 297 of the dict_copy function, a pointer variable named copy is defined. This pointer variable is allocated a dynamic memory area by the dict_alloc function at line 305. The copy variable is returned at line 355, as shown in the diagram below:https://github.com/LuMingYinDetect/vim_defects/blob/main/vim_2.png
3.Therefore, after the execution of dict_copy, the pointer d1 actually points to a newly allocated dynamic memory area. The content of this dynamic memory area is identical to the original content of d1. When the condition at line 1302 of the program holds true, the function returns at line 1303. During this process, the dynamic memory area pointed to by the pointer d1 is neither used nor freed, thus constituting a memory leak defect, as shown in the diagram below:https://github.com/LuMingYinDetect/vim_defects/blob/main/vim_3.png

Expected behaviour

Fixing the memory leak defect.

Version of Vim

9.1.0188

Environment

Ubuntu 22.04

Logs and stack traces

No response

@zeertzjq
Copy link
Member

LSAN doesn't catch this because the dictionary is garbage-collected, and this applies to list_extend_func() as well.

@LuMingYinDetect
Copy link
Author

LSAN doesn't catch this because the dictionary is garbage-collected, and this applies to list_extend_func() as well.

Thank you for your quick response!

@zeertzjq
Copy link
Member

zeertzjq commented Mar 20, 2024

I don't think this should be closed.

@LuMingYinDetect
Copy link
Author

I don't think this should be closed.

Hello! Are you suggesting that this might be a suspected memory leak defect? I initially thought it was a false alarm, so I closed the issue. I have now reopened it.

@zeertzjq
Copy link
Member

Calling extendnew() with invalid type for the third argument repeated does cause memory usage to keep increasing, and it doesn't go down until Vim is closed:

for i in range(1000000)
  silent! call extendnew({}, {}, {})
endfor
for i in range(1000000)
  silent! call extendnew([], [], [])
endfor

@LuMingYinDetect
Copy link
Author

Calling extendnew() with invalid type for the third argument repeated does cause memory usage to keep increasing, and it doesn't go down until Vim is closed:

for i in range(1000000)
  silent! call extendnew({}, {}, {})
endfor
for i in range(1000000)
  silent! call extendnew([], [], [])
endfor

Thank you for your patient response! I believe this indeed is a memory leak defect, and fixing it could be considered.

chrisbra added a commit to chrisbra/vim that referenced this issue Apr 15, 2024
fixes: vim#14477
fixes: vim#14238
Signed-off-by: Christian Brabandt <cb@256bit.org>
zeertzjq added a commit to zeertzjq/neovim that referenced this issue Apr 16, 2024
Problem:  a few memory leaks are found
          (LuMingYinDetect )
Solution: properly free the memory

Fixes the following problems:
- Memory leak in f_maplist()
  fixes: vim/vim#14486

- Memory leak in option.c
  fixes: vim/vim#14485

- Memory leak in f_resolve()
  fixes: vim/vim#14484

- Memory leak in f_autocmd_get()
  related: vim/vim#14474

- Memory leak in dict_extend_func()
  fixes: vim/vim#14477
  fixes: vim/vim#14238

closes: vim/vim#14517

vim/vim@29269a7

Co-authored-by: Christian Brabandt <cb@256bit.org>
zeertzjq added a commit to neovim/neovim that referenced this issue Apr 16, 2024
Problem:  a few memory leaks are found
          (LuMingYinDetect )
Solution: properly free the memory

Fixes the following problems:
- Memory leak in f_maplist()
  fixes: vim/vim#14486

- Memory leak in option.c
  fixes: vim/vim#14485

- Memory leak in f_resolve()
  fixes: vim/vim#14484

- Memory leak in f_autocmd_get()
  related: vim/vim#14474

- Memory leak in dict_extend_func()
  fixes: vim/vim#14477
  fixes: vim/vim#14238

closes: vim/vim#14517

vim/vim@29269a7

Co-authored-by: Christian Brabandt <cb@256bit.org>
famiu pushed a commit to famiu/neovim that referenced this issue Apr 18, 2024
Problem:  a few memory leaks are found
          (LuMingYinDetect )
Solution: properly free the memory

Fixes the following problems:
- Memory leak in f_maplist()
  fixes: vim/vim#14486

- Memory leak in option.c
  fixes: vim/vim#14485

- Memory leak in f_resolve()
  fixes: vim/vim#14484

- Memory leak in f_autocmd_get()
  related: vim/vim#14474

- Memory leak in dict_extend_func()
  fixes: vim/vim#14477
  fixes: vim/vim#14238

closes: vim/vim#14517

vim/vim@29269a7

Co-authored-by: Christian Brabandt <cb@256bit.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants