Skip to content

Commit

Permalink
vim-patch:9.1.0341: Problem: a few memory leaks are found (neovim#28382)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and famiu committed Apr 18, 2024
1 parent 2f371ad commit 36307a1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 40 deletions.
25 changes: 16 additions & 9 deletions src/nvim/generators/gen_options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,29 @@ local function dump_option(i, o)
w(get_cond(o.enable_if))
end

-- Hidden options cannot have a varname.
assert(not o.hidden or not o.varname)
-- An option cannot be both hidden and immutable.
assert(not o.hidden or not o.immutable)
-- enable_if cannot be used with hidden or immutable.
assert(not o.enable_if or not (o.hidden or o.immutable))

local has_var = true
if o.varname then
w(' .var=&' .. o.varname)
elseif o.hidden or o.immutable then
-- Hidden and immutable options can directly point to the default value.
elseif o.immutable then
-- Immutable options can directly point to the default value.
w((' .var=&options[%u].def_val'):format(i - 1))
elseif o.hidden then
-- Hidden options don't have a variable pointer.
w(' .var=NULL')
elseif #o.scope == 1 and o.scope[1] == 'window' then
w(' .var=VAR_WIN')
else
has_var = false
end
-- `enable_if = false` should be present iff there is no variable.
assert((o.enable_if == false) == not has_var)
w(' .hidden=' .. (o.hidden and 'true' or 'false'))
w(' .immutable=' .. (o.immutable and 'true' or 'false'))
-- `hidden` is always false for the true branch of enable_if.
w(' .hidden=' .. (o.enable_if and 'false' or (o.hidden and 'true' or 'false')))
if o.immutable then
w(' .immutable=kOptImmutable' .. o.immutable:sub(1, 1):upper() .. o.immutable:sub(2))
end
if #o.scope == 1 and o.scope[1] == 'global' then
w(' .indir=PV_NONE')
else
Expand Down Expand Up @@ -213,6 +218,8 @@ local function dump_option(i, o)
w('#else')
w(' .var=NULL')
w(' .indir=PV_NONE')
-- `hidden` is always true for the false branch of enable_if
w(' .hidden=true')
w('#endif')
end
if o.defaults then
Expand Down
14 changes: 7 additions & 7 deletions src/nvim/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -3345,7 +3345,7 @@ static char *option_get_valid_types(OptIndex opt_idx)
/// @return True if option is hidden, false otherwise. Returns false if option name is invalid.
bool is_option_hidden(OptIndex opt_idx)
{
return opt_idx == kOptInvalid ? false : get_varp(&options[opt_idx]) == NULL;
return opt_idx == kOptInvalid ? false : options[opt_idx].hidden;
}

/// Get option flags.
Expand Down Expand Up @@ -3484,8 +3484,8 @@ static const char *did_set_option(OptIndex opt_idx, void *varp, OptVal old_value
if (direct || opt->hidden) {
// Don't do any extra processing if setting directly or if option is hidden.
}
// Disallow changing immutable options.
else if (opt->immutable && !optval_equal(old_value, new_value)) {
// Disallow changing certain immutable options.
else if (opt->immutable == kOptImmutableError && !optval_equal(old_value, new_value)) {
errmsg = e_unsupportedoption;
}
// Disallow changing some options from secure mode.
Expand All @@ -3509,9 +3509,9 @@ static const char *did_set_option(OptIndex opt_idx, void *varp, OptVal old_value
restore_chartab = did_set_cb_args.os_restore_chartab;
}

// If option is hidden or if an error is detected, restore the previous value and don't do any
// further processing.
if (opt->hidden || errmsg != NULL) {
// If option is immutable and changing its value needs to be ignored, or if an error is detected,
// restore the previous value and don't do any further processing.
if (opt->immutable == kOptImmutableIgnore || errmsg != NULL) {
set_option_varp(opt_idx, varp, old_value, true);
// When resetting some values, need to act on it.
if (restore_chartab) {
Expand Down Expand Up @@ -4226,7 +4226,7 @@ static int optval_default(OptIndex opt_idx, void *varp)
vimoption_T *opt = &options[opt_idx];

// Hidden or immutable options always use their default value.
if (varp == NULL || opt->hidden || opt->immutable) {
if (varp == NULL || opt->hidden || opt->immutable != kOptImmutableNone) {
return true;
}

Expand Down
11 changes: 9 additions & 2 deletions src/nvim/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ typedef enum {
// buffers. Indicate this by setting "var" to VAR_WIN.
#define VAR_WIN ((char *)-1)

/// Immutable options have a value that can be fetched, but cannot be changed.
typedef enum {
kOptImmutableNone = 0, ///< Option is mutable.
kOptImmutableIgnore, ///< Option is immutable, ignore any attempt to set its value.
kOptImmutableError, ///< Option is immutable, error when trying to set its value.
} OptImmutable;

typedef struct {
char *fullname; ///< full option name
char *shortname; ///< permissible abbreviation
Expand All @@ -49,8 +56,8 @@ typedef struct {
///< buffer-local option: global value
idopt_T indir; ///< global option: PV_NONE;
///< local option: indirect option index
bool hidden; ///< option is hidden, any attempt to set its value will be ignored.
bool immutable; ///< option is immutable, trying to set its value will give an error.
bool hidden; ///< option is hidden, cannot get/set its value
OptImmutable immutable; ///< option immutability, see OptImmutable

/// callback function to invoke after an option is modified to validate and
/// apply the new value.
Expand Down
44 changes: 22 additions & 22 deletions src/nvim/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
--- @field pv_name? string
--- @field type 'boolean'|'number'|'string'
--- @field hidden? boolean
--- @field immutable? boolean
--- @field immutable? 'ignore'|'error'
--- @field list? 'comma'|'onecomma'|'commacolon'|'onecommacolon'|'flags'|'flagscomma'
--- @field scope vim.option_scope[]
--- @field deny_duplicates? boolean
Expand Down Expand Up @@ -91,11 +91,11 @@ return {
{
abbreviation = 'al',
defaults = { if_true = 224 },
enable_if = false,
full_name = 'aleph',
scope = { 'global' },
short_desc = N_('ASCII code of the letter Aleph (Hebrew)'),
type = 'number',
hidden = true,
},
{
abbreviation = 'ari',
Expand Down Expand Up @@ -791,11 +791,11 @@ return {
current Use the current directory.
{path} Use the specified directory
]=],
enable_if = false,
full_name = 'browsedir',
scope = { 'global' },
short_desc = N_('which directory to start browsing in'),
type = 'string',
hidden = true,
},
{
abbreviation = 'bh',
Expand Down Expand Up @@ -1342,7 +1342,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'cpt',
Expand Down Expand Up @@ -2301,7 +2301,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'emo',
Expand Down Expand Up @@ -3720,12 +3720,12 @@ return {
try to keep 'lines' and 'columns' the same when adding and
removing GUI components.
]=],
enable_if = false,
full_name = 'guioptions',
list = 'flags',
scope = { 'global' },
short_desc = N_('GUI: Which components and options are used'),
type = 'string',
hidden = true,
},
{
abbreviation = 'gtl',
Expand All @@ -3744,13 +3744,13 @@ return {
present in 'guioptions'. For the non-GUI tab pages line 'tabline' is
used.
]=],
enable_if = false,
full_name = 'guitablabel',
modelineexpr = true,
redraw = { 'current_window' },
scope = { 'global' },
short_desc = N_('GUI: custom label for a tab page'),
type = 'string',
hidden = true,
},
{
abbreviation = 'gtt',
Expand All @@ -3762,12 +3762,12 @@ return {
let &guitabtooltip = "line one\nline two"
<
]=],
enable_if = false,
full_name = 'guitabtooltip',
redraw = { 'current_window' },
scope = { 'global' },
short_desc = N_('GUI: custom tooltip for a tab page'),
type = 'string',
hidden = true,
},
{
abbreviation = 'hf',
Expand Down Expand Up @@ -3901,7 +3901,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'hkp',
Expand All @@ -3910,7 +3910,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'hls',
Expand Down Expand Up @@ -4009,11 +4009,11 @@ return {
English characters directly, e.g., when it's used to type accented
characters with dead keys.
]=],
enable_if = false,
full_name = 'imcmdline',
scope = { 'global' },
short_desc = N_('use IM when starting to edit a command line'),
type = 'boolean',
hidden = true,
},
{
abbreviation = 'imd',
Expand All @@ -4027,11 +4027,11 @@ return {
Currently this option is on by default for SGI/IRIX machines. This
may change in later releases.
]=],
enable_if = false,
full_name = 'imdisable',
scope = { 'global' },
short_desc = N_('do not use the IM in any mode'),
type = 'boolean',
hidden = true,
},
{
abbreviation = 'imi',
Expand Down Expand Up @@ -4308,7 +4308,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'isf',
Expand Down Expand Up @@ -5159,7 +5159,7 @@ return {
scope = { 'global' },
short_desc = N_('maximum nr of combining characters displayed'),
type = 'number',
hidden = true,
immutable = 'ignore',
},
{
abbreviation = 'mfd',
Expand Down Expand Up @@ -5655,13 +5655,13 @@ return {
indicate no input when the hit-enter prompt is displayed (since
clicking the mouse has no effect in this state.)
]=],
enable_if = false,
full_name = 'mouseshape',
list = 'onecomma',
scope = { 'global' },
short_desc = N_('shape of the mouse pointer in different modes'),
tags = { 'E547' },
type = 'string',
hidden = true,
},
{
abbreviation = 'mouset',
Expand Down Expand Up @@ -5809,11 +5809,11 @@ return {
Note that on Windows editing "aux.h", "lpt1.txt" and the like also
result in editing a device.
]=],
enable_if = false,
full_name = 'opendevice',
scope = { 'global' },
short_desc = N_('allow reading/writing devices on MS-Windows'),
type = 'boolean',
hidden = true,
},
{
abbreviation = 'opfunc',
Expand Down Expand Up @@ -5886,11 +5886,11 @@ return {
{
abbreviation = 'pt',
defaults = { if_true = '' },
enable_if = false,
full_name = 'pastetoggle',
scope = { 'global' },
short_desc = N_('No description'),
type = 'string',
hidden = true,
},
{
abbreviation = 'pex',
Expand Down Expand Up @@ -6060,7 +6060,7 @@ return {
scope = { 'global' },
short_desc = N_('enable prompt in Ex mode'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'pb',
Expand Down Expand Up @@ -6317,7 +6317,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
defaults = { if_true = 2 },
Expand Down Expand Up @@ -8778,11 +8778,11 @@ return {
{
abbreviation = 'tenc',
defaults = { if_true = '' },
enable_if = false,
full_name = 'termencoding',
scope = { 'global' },
short_desc = N_('Terminal encoding'),
type = 'string',
hidden = true,
},
{
abbreviation = 'tgc',
Expand Down Expand Up @@ -8856,7 +8856,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'tw',
Expand Down Expand Up @@ -9101,7 +9101,7 @@ return {
scope = { 'global' },
short_desc = N_('No description'),
type = 'boolean',
immutable = true,
immutable = 'error',
},
{
abbreviation = 'udir',
Expand Down

0 comments on commit 36307a1

Please sign in to comment.