Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak using PicocParse() #142

Closed
GoogleCodeExporter opened this issue Oct 14, 2015 · 5 comments
Closed

Memory leak using PicocParse() #142

GoogleCodeExporter opened this issue Oct 14, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 20 Oct 2011 at 9:24

@GoogleCodeExporter
Copy link
Author

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

Original comment by [email protected] on 1 Sep 2012 at 6:46

  • Changed state: Started

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 20 Dec 2012 at 9:55

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 20 Dec 2012 at 9:59

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 23 Feb 2013 at 4:43

@GoogleCodeExporter
Copy link
Author

Fixed in r585. Thanks.

Original comment by [email protected] on 23 Feb 2013 at 10:57

  • Changed state: Verified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant