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
Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

809 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