fb39ca4 / picoc

Automatically exported from code.google.com/p/picoc
0 stars 0 forks source link

Memory leak using PicocParse() #142

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Initialalize picoc - PicocInitialise(StackSize);
2. Execute:
 PicocParse( "x", "xxx", sizeof( "xxx"), TRUE, TRUE, FALSE, FALSE);
3. Shut down picoc - PicocCleanup();

Note: a longjmp handler must be set up before the call to PicocParse():

   if (PicocPlatformSetExitPoint())
   {
      PicocCleanup();
      return PicocExitValue;
   }
   PicocParse( ...

What is the expected output? What do you see instead?
In my case (Visual Studio C++ 2010 Express w/debugging and memory leak 
checking) this produces this leak:

Dumping objects ->
d:\projects\testsystem\code\test\picoc-svn\heap.c(149) : {1061} normal block at 
0x00797FA0, 8 bytes long.
 Data: <- \ y ] > 2D 00 5C 7F 79 00 5D 04 
Object dump complete.
The program '[2504] picoc2010.exe: Native' has exited with code 1 (0x1).

Provoking different errors produces different but similar leaks:

Executing "int 123;":

Detected memory leaks!
Dumping objects ->
d:\projects\testsystem\code\test\picoc-svn\heap.c(149) : {1060} normal block at 
0x007A7F50, 9 bytes long.
 Data: <6 1 {2 ] > 36 00 31 04 7B 32 08 5D 09 
Object dump complete.
The program '[3444] picoc2010.exe: Native' has exited with code 1 (0x1).

What version of the product are you using? On what operating system?
Latest read-only from SVN (dated October 19, 2011).

Please provide any additional information below.

Original issue reported on code.google.com by jjohans...@gmail.com on 20 Oct 2011 at 9:24

GoogleCodeExporter commented 8 years ago
I was unable to reproduce this issue using just "int 123;" as the program. What 
program were you using?

Original comment by zik.sale...@gmail.com on 1 Sep 2012 at 6:46

GoogleCodeExporter commented 8 years ago
Hi! Sorry for the (very) late response! Here is the code fragment used:

#define PICOC_STACK_SIZE (128*1024)              /* space for the the stack */

int main(int argc, char **argv)
{
    int ParamCount = 1;
    int DontRunMain = FALSE;
    int StackSize = getenv("STACKSIZE") ? atoi(getenv("STACKSIZE")) : PICOC_STACK_SIZE;

    if (argc < 2)
    {
        printf("Format: picoc <csource1.c>... [- <arg1>...]    : run a program (calls main() to start it)\n"
               "        picoc -s <csource1.c>... [- <arg1>...] : script mode - runs the program without calling main()\n"
               "        picoc -i                               : interactive mode\n");
        exit(1);
    }

    PicocInitialise(StackSize);

    if (strcmp(argv[ParamCount], "-s") == 0 || strcmp(argv[ParamCount], "-m") == 0)
    {
        DontRunMain = TRUE;
        PicocIncludeAllSystemHeaders();
        ParamCount++;
    }

    if (argc > ParamCount && strcmp(argv[ParamCount], "-i") == 0)
    {
        PicocIncludeAllSystemHeaders();
        PicocParseInteractive(TRUE);
    }
    else if( argc > ParamCount && strcmp(argv[ParamCount], "-z") == 0)
    {
        if (PicocPlatformSetExitPoint())
        {
            PicocCleanup();
            printf( "Error!\n");
_CrtDumpMemoryLeaks();
            return PicocExitValue;
        }
#define CODE1 "int 123;"
        PicocIncludeAllSystemHeaders();
        printf( "z-option\n");
        PicocParse( "filename3.c", CODE1, sizeof( CODE2), TRUE, TRUE, FALSE, FALSE); 
    }
    else
    {
    ...
    }

    PicocCleanup();
_CrtDumpMemoryLeaks();
    return PicocExitValue;
}

I get this output on the console:

z-option
int 123;
^
filename3.c:1: identifier expected
Error!
Press any key to continue . . .

And this output from VC:

'picoc2010.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
Detected memory leaks!
Dumping objects ->
{1061} normal block at 0x00866E60, 9 bytes long.
 Data: <6 1 {2 ] > 36 00 31 04 7B 32 08 5D 09 
Object dump complete.
The program '[4296] picoc2010.exe: Native' has exited with code 1 (0x1).

Original comment by jjohans...@gmail.com on 20 Dec 2012 at 9:55

GoogleCodeExporter commented 8 years ago
Sorry, when pasting in the code above I made a mistake. Should look like this:

...
#define CODE2 "int 123;"
        PicocIncludeAllSystemHeaders();
        printf( "z-option\n");
        PicocParse( "filename3.c", CODE2, sizeof( CODE2), TRUE, TRUE, FALSE, FALSE); 
...

Original comment by jjohans...@gmail.com on 20 Dec 2012 at 9:59

GoogleCodeExporter commented 8 years ago
In the Lex.c source file, change the following function. It should fix the 
memory leak!

/* deallocate */
void LexCleanup(Picoc *pc)
{
    LexInteractiveClear(pc, NULL);

    int Count;
    for (Count = 0; Count < sizeof(ReservedWords) / sizeof(struct ReservedWord); Count++)
        TableDelete(pc, &pc->ReservedWordTable, TableStrRegister(pc, ReservedWords[Count].Word));
}

Original comment by mmass...@gmail.com on 23 Feb 2013 at 4:43

GoogleCodeExporter commented 8 years ago
Fixed in r585. Thanks.

Original comment by zik.sale...@gmail.com on 23 Feb 2013 at 10:57