mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(tui): avoid memory leak and compiler warning on Windows (#34225)
Problem: On Windows, the value of `term` is overwritten without freeing
the old allocated value, which may lead to a memory leak.
GCC also gives a "incompatible pointer type" warning about
passing `*term` to os_tty_guess_term().
Solution: Don't override the old allocated value, and copy the guessed
value to `term` if its old value is NULL.
(cherry picked from commit fb5a51e775
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
ee06d0e64d
commit
70b4e7948f
@@ -127,9 +127,6 @@ bool os_env_exists(const char *name)
|
|||||||
/// Sets an environment variable.
|
/// Sets an environment variable.
|
||||||
///
|
///
|
||||||
/// Windows (Vim-compat): Empty string (:let $FOO="") undefines the env var.
|
/// Windows (Vim-compat): Empty string (:let $FOO="") undefines the env var.
|
||||||
///
|
|
||||||
/// @warning Existing pointers to the result of os_getenv("foo") are
|
|
||||||
/// INVALID after os_setenv("foo", …).
|
|
||||||
int os_setenv(const char *name, const char *value, int overwrite)
|
int os_setenv(const char *name, const char *value, int overwrite)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
|
@@ -387,10 +387,12 @@ static void terminfo_start(TUIData *tui)
|
|||||||
|
|
||||||
const char *term = os_getenv("TERM");
|
const char *term = os_getenv("TERM");
|
||||||
#ifdef MSWIN
|
#ifdef MSWIN
|
||||||
os_tty_guess_term(&term, tui->out_fd);
|
const char *guessed_term = NULL;
|
||||||
os_setenv("TERM", term, 1);
|
os_tty_guess_term(&guessed_term, tui->out_fd);
|
||||||
// Old os_getenv() pointer is invalid after os_setenv(), fetch it again.
|
if (term == NULL && guessed_term != NULL) {
|
||||||
term = os_getenv("TERM");
|
term = xstrdup(guessed_term);
|
||||||
|
os_setenv("TERM", guessed_term, 1);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Set up unibilium/terminfo.
|
// Set up unibilium/terminfo.
|
||||||
|
Reference in New Issue
Block a user