[vim/vim] fix: improve memory management and code style (PR #17984)

13 views
Skip to first unread message

glepnir

unread,
Aug 13, 2025, 7:53:10 AMAug 13
to vim/vim, Subscribed

Problem:

  • Missing cleanup of lmatchpos lists causing memory leaks
  • Missing error handling for list operations
  • Use of malloc() instead of Vim's alloc() functions
  • Inconsistent C-style comments
  • Missing null pointer checks for memory allocation
  • Incorrect use of vim_free() for list objects

Solution:

  • Add proper cleanup of lmatchpos in done section using list_unref()
  • Set lmatchpos to NULL after successful transfer to avoid confusion
  • Add error handling for list_append_tv() failures
  • Replace malloc() with alloc() and add null pointer checks
  • Convert C-style comments to C++ style for consistency
  • Fix vim_free() calls to use list_free() for list objects

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/17984

Commit Summary

  • 20d4dae fix: improve memory management and code style

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984@github.com>

zeertzjq

unread,
Aug 13, 2025, 8:01:53 AMAug 13
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/fuzzy.c:

> +
+	if (items[i].lmatchpos)
+	    list_unref(items[i].lmatchpos);

I don't think using list_unref() here makes sense. If list_append_list() fails, the remaining lists' reference counts are 0, so it's better to just use list_free() directly.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/review/3115588843@github.com>

glepnir

unread,
Aug 13, 2025, 8:15:23 AMAug 13
to vim/vim, Subscribed

@glepnir commented on this pull request.


In src/fuzzy.c:

> +
+	if (items[i].lmatchpos)
+	    list_unref(items[i].lmatchpos);

when 1 fails, 0 succeeds. the li->lv_refcount of 0 is 1. so using list_unref here is more safer 🤔


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/review/3115679260@github.com>

zeertzjq

unread,
Aug 13, 2025, 8:22:58 AMAug 13
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/fuzzy.c:

> +
+	if (items[i].lmatchpos)
+	    list_unref(items[i].lmatchpos);

I can't understand what you are talking about.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/review/3115739609@github.com>

glepnir

unread,
Aug 13, 2025, 8:26:19 AMAug 13
to vim/vim, Push

@glepnir pushed 1 commit.

  • 465a7e9 fix: improve memory management and code style


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/before/20d4dae6690564a2330f42c8ea540a83909d1d61/after/465a7e92c794b0656e5951595bee69ddaaeab9a4@github.com>

zeertzjq

unread,
Aug 13, 2025, 8:26:54 AMAug 13
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/fuzzy.c:

> +
+	if (items[i].lmatchpos)
+	    list_unref(items[i].lmatchpos);

No, if list_append_list() succeeds, you already set items[i].lmatchpos to NULL, so this isn't called. Furthermore, for lists that are successfully added to retlist, they should be freed along with retlist (which is by the caller), not here.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/review/3115765726@github.com>

zeertzjq

unread,
Aug 13, 2025, 8:28:48 AMAug 13
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/fuzzy.c:

> +
+	if (items[i].lmatchpos)
+	    list_unref(items[i].lmatchpos);

And you also need to change list_unref to list_free in the commit message.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/review/3115777204@github.com>

glepnir

unread,
Aug 13, 2025, 8:31:38 AMAug 13
to vim/vim, Subscribed

@glepnir commented on this pull request.


In src/fuzzy.c:

> +
+	if (items[i].lmatchpos)
+	    list_unref(items[i].lmatchpos);

yes, they should be free by fmatchlist. I have modified and updated


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/review/3115791196@github.com>

Christian Brabandt

unread,
Aug 13, 2025, 4:02:01 PMAug 13
to vim/vim, Subscribed
chrisbra left a comment (vim/vim#17984)

thanks


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/c3185490040@github.com>

Christian Brabandt

unread,
Aug 13, 2025, 4:07:56 PMAug 13
to vim/vim, Subscribed

Closed #17984 via 17a6d69.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/17984/issue_event/19144740322@github.com>

Reply all
Reply to author
Forward
0 new messages