help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory management of all_visible_functions return


From: Robert E. Griffith
Subject: Re: memory management of all_visible_functions return
Date: Wed, 20 Apr 2022 15:52:29 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0


`Invisible' variables are variables that have been assigned attributes but
not values, so they are technically unset.

So what is the practical consequence of them not being visible?

   $*cat /tmp/test.sh*
   #!/usr/bin/env bash
   myvar="hello"
   foo() {
        local myvar
        echo "myvar='$myvar'"
   }
   foo
   $*/tmp/test.sh*
   myvar=''

If myvar in the function foo() is invisible because I did not set a value, I would think that this would have printed "myvar='hello'"

--BobG


On 4/20/22 14:21, Chet Ramey wrote:
On 4/20/22 1:28 PM, Robert E. Griffith wrote:
I am calling all_visible_functions() in my loadable builtin. When I am done
with the SHELL_VAR** it returns, should I xfree() it?
Yes.

The reason I am asking is I followed the two places its called in the code
and I don't see it being freed. They are pretty complicated so I could just
be missing it but I thought I would ask. I believe that the returned
variable is allocated in vlist_alloc() in variables.c.
I'll look at the one in the programmable completion code. valgrind doesn't
report any leaks there.

And while I am asking, what is the concept of invisible variables and
functions? Do they correspond to something we see in BASH scripts or is it
an optimization detail?
`Invisible' variables are variables that have been assigned attributes but
not values, so they are technically unset.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]