Maybe I found memory leak

classic Classic list List threaded Threaded
6 messages Options
framer framer
Reply | Threaded
Open this post in threaded view
|

Maybe I found memory leak

Hi. In function luaY_parser (lparser.c)
Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff, const char *name) {
  struct LexState lexstate;
  struct FuncState *pfuncstate = (struct FuncState*)ext_lua_malloc(sizeof(struct FuncState));  <-- !!! memory allocation 
  Proto *res;
...
 chunk(&lexstate); <-- !!! in this place maybe appearance exception (for example" stdin:1: unexpected symbol near '+') and will be execution luaD_throw   
.....
 ext_lua_free(pfuncstate); <-- !!! if was exception in chunk (see up) it is newer execution 


best regards
jbsnyder jbsnyder
Reply | Threaded
Open this post in threaded view
|

Re: Maybe I found memory leak

Hi -

I haven't looked into this at all, but do you have any details about
conditions that give rise to this, particular code that you think
might be the culprit or anything else that leads you to narrow it down
to this particular function?

Best.

-jsnyder

On Wed, Jun 13, 2012 at 10:51 AM, framer <[hidden email]> wrote:

> Hi. In function luaY_parser (lparser.c)
>
>
>
> best regards
>
> --
> View this message in context: http://elua-development.2368040.n2.nabble.com/Maybe-I-found-memory-leak-tp7577478.html
> Sent from the eLua Development mailing list archive at Nabble.com.
> _______________________________________________
> eLua-dev mailing list
> [hidden email]
> https://lists.berlios.de/mailman/listinfo/elua-dev



--
James Snyder
Biomedical Engineering
Northwestern University
http://fanplastic.org/key.txt
ph: (847) 448-0386
_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev
framer framer
Reply | Threaded
Open this post in threaded view
|

Re: Maybe I found memory leak

I think the problem is in luaD_throw function. Probably luaD_throw function to launch longjmp function. When a "non-local goto" is executed via setjmp/longjmp, normal "stack unwinding" does not occur and therefore, any required cleanup actions such as closing file descriptors, flushing buffers, freeing heap-allocated memory, etc., do not occur.
BogdanM BogdanM
Reply | Threaded
Open this post in threaded view
|

Re: Maybe I found memory leak

Hi,

On Wed, Jun 13, 2012 at 10:19 PM, framer <[hidden email]> wrote:
> I think the problem is in luaD_throw function. Probably luaD_throw function
> to launch longjmp function. When a "non-local goto" is executed via
> setjmp/longjmp, normal "stack unwinding" does not occur and therefore, any
> required cleanup actions such as closing file descriptors, flushing buffers,
> freeing heap-allocated memory, etc., do not occur.

Lua takes care of its allocated memory very carefully. It takes care
of freeing all objects when the interpreter exits, thus things are
safe on the Lua side. On the C side, if you're exporting modules with
userdata that have a proper __gc metamethod, you're also safe.
Something similar happens to file descriptors because they are not
actual file descriptors, but "managed" file descriptors. If you look
at liolib.c, you'll see that a file userdata (as returned by io.open)
has an associated __gc metamethod that takes care of closing the file.
That said, there are reasons to worry. Any C module that doesn't play
nicely with __gc might leak resources when luaD_throw returns. The
sockets in eLua (as returned by the net module) are one example.

Best,
Bogdan

>
> --
> View this message in context: http://elua-development.2368040.n2.nabble.com/Maybe-I-found-memory-leak-tp7577478p7577480.html
> Sent from the eLua Development mailing list archive at Nabble.com.
> _______________________________________________
> eLua-dev mailing list
> [hidden email]
> https://lists.berlios.de/mailman/listinfo/elua-dev
_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev
framer framer
Reply | Threaded
Open this post in threaded view
|

Re: Maybe I found memory leak

I can presentation this case on screencast.  eLua works on software simulator. All allocation function (malloc, realloc, free) run through wrapper and we can logs allocation memory in real time. It is presentation on http://ftp.vado.pl:10080/an/other/test.zip (~25Mb).  Problem come in when interpreter obtain syntactic error. Debug session presentation on http://ftp.vado.pl:10080/an/other/test2.zip (~23Mb).   If  interpreter obtain syntactic error then break function luaY_parser in chunk(&lexstate); and not free struct FuncState *pfuncstate.
BogdanM BogdanM
Reply | Threaded
Open this post in threaded view
|

Re: Maybe I found memory leak

On Thu, Jun 14, 2012 at 11:29 AM, framer <[hidden email]> wrote:

> I can presentation this case on screencast.  eLua works on software
> simulator. All allocation function (malloc, realloc, free) run through
> wrapper and we can logs allocation memory in real time. It is presentation
> on  http://ftp.vado.pl:10080/an/other/test.zip
> http://ftp.vado.pl:10080/an/other/test.zip  (~25Mb).  Problem come in when
> interpreter obtain syntactic error. Debug session presentation on
> http://ftp.vado.pl:10080/an/other/test2.zip
> http://ftp.vado.pl:10080/an/other/test2.zip  (~23Mb).   If  interpreter
> obtain syntactic error then break function /luaY_parser/ in
> /chunk(&lexstate);/ and not free struct FuncState *pfuncstate.

Ah, OK, I think I understand now. Thanks for your report! That's most
likely a result of some of my patches to the Lua source tree. I'll
open a bug on this.

Best,
Bogdan

>
> --
> View this message in context: http://elua-development.2368040.n2.nabble.com/Maybe-I-found-memory-leak-tp7577478p7577488.html
> Sent from the eLua Development mailing list archive at Nabble.com.
> _______________________________________________
> eLua-dev mailing list
> [hidden email]
> https://lists.berlios.de/mailman/listinfo/elua-dev
_______________________________________________
eLua-dev mailing list
[hidden email]
https://lists.berlios.de/mailman/listinfo/elua-dev