Solved

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

Posted on 2006-06-15
4
841 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
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 63 total points
Comment Utility
>>       =>         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 62 total points
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now