Solved

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

Posted on 2006-06-15
4
850 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
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 62 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

914 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

17 Experts available now in Live!

Get 1:1 Help Now