Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VC++ 6.0 : system() library call is leaking

Posted on 2006-06-15
4
Medium Priority
?
875 Views
Last Modified: 2012-05-05
Hi,

sytem() library call caused 776 bytes memory leak.

Could u pls explain to delete this memory.

System is spawning a process to execute the given command .
The   CreateProcessW function from  kernel32.dll has allocated some memory from the heap which it has not deallocated. This seems to be causing the memory leak.
How do we get around this problem?
The following is the snapshot of Purify showing the leak.

-------------------------------------------------------------------------------
[W] MLK: Memory leak of 776 bytes from 2 blocks allocated in CreateProcessW [kernel32.dll]

    Allocation location
        RtlAllocateHeap [NTDLL.dll]
        CreateProcessW [kernel32.dll]
        dospawn        [dospawn.c:188]
                                                         NULL,
                                                         &StartupInfo,
                                                         &ProcessInformation
         =>                                            );
           
                    dosretval = GetLastError();
                    _free_crt( StartupInfo.lpReserved2 );
        comexecmd      [spawnve.c:122]
            #ifdef WPRFLAG
                    rc = _wdospawn(mode, name, argblk, envblk);
            #else  /* WPRFLAG */
         =>         rc = _dospawn(mode, name, argblk, envblk);
            #endif  /* WPRFLAG */
            #else  /* EXECVE */
            #ifdef WPRFLAG
        spawnve        [spawnve.c:260]
            #ifdef WPRFLAG
                                    rc = wcomexecmd(mode, pathname, argv, envp);
            #else  /* WPRFLAG */
         =>                         rc = comexecmd(mode, pathname, argv, envp);
            #endif  /* WPRFLAG */
           
            #else  /* EXECVE */
        system         [system.c:69]
           
                    if (argv[0])    /* Do not try to spawn the null string */
                            if ((catch = _tspawnve(_P_WAIT,argv[0],argv,NULL)) != -1
         =>                 || (errno != ENOENT && errno != EACCES))
                                    return(catch);
           
                    /* No COMSPEC so set argv[0] to what COMSPEC should be. */
       
         =>         i=system(pCopyFile);
                    if(0!=i)
-------------------------------------------------------------------------------
0
Comment
Question by:k_kalyan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 252 total points
ID: 16913517
>>       =>         i=system(pCopyFile);

If you want to copy a file, use 'CopyFile()', e.g.

CopyFile("c:\\tmp\\file1.txt","c:\\tmp\\file2.txt", FALSE);

BTW, Purify seems to be wrong about the error. Just examine 'dospawn.c'.
0
 
LVL 11

Assisted Solution

by:cup
cup earned 248 total points
ID: 17027241
Is it a one off leak or does it leak every time you call the routine?  Most systems have a one off leak that isn't worth bothering about because when the process is killed, the OS will get rid of it for you.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question