Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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 …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.

770 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