Intro Download and install Frequently Asked Questions Tips and tricks

Homepage







© J.C. Kessels 2009
MyDefrag Forum
June 20, 2013, 08:16:08 am *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Is there memory leak?  (Read 1944 times)
reika
JkDefrag Junior
**
Posts: 8


View Profile
« on: July 23, 2007, 11:23:41 am »

Hi,
I read the source code and I have a question.
The function AddArrayString() allocated memory.
But I can not find souce code to free Data.Excludes.
Is there memory leak if "-e" parameter used?

Here Data.SpaceHogs has been freed. but not Data.Excludes
/* Cleanup. */
  if (Data.SpaceHogs != NULL) {
    for (i = 0; Data.SpaceHogs != NULL; i++) free(Data.SpaceHogs);
    free(Data.SpaceHogs);
    }

BTW: My English is poor.

Thank you.
Logged
jeroen
Administrator
JkDefrag Hero
*****
Posts: 7156



View Profile WWW
« Reply #1 on: July 24, 2007, 07:06:05 am »

The Excludes array is a parameter, it is not allocated inside the library and therefore not freed. It must be freed outside the library by the caller. The same applies to the SpaceHogs. The code you have found inside the library will free the internal copy of the spacehogs array, not the original input parameter.

In other words, the Excludes and the Spacehogs arrays should be freed in the JkDefragWindows.cpp, JkDefragCmd.cpp, and JkDefragScreenSaver2.cpp sources. It's not there, but not very important because just after returning from the library these programs will stop.
Logged
reika
JkDefrag Junior
**
Posts: 8


View Profile
« Reply #2 on: July 24, 2007, 08:39:16 am »

Smiley

I see.

Jeffrey Richter《Programming Applications for Microsoft Windows》chapter 3

"So, your application can leak kernel objects while it runs, but when your process terminates, the system guarantees that everything is cleaned up properly. By the way, this is true for all objects, resources, and memory blocks: when a process terminates, the system ensures that your process leaves nothing behind."

JkDefragWindows.cpp not call free() function.
Hm~~, Windows will cleanup all memory when JKD finished.
thus, "not very important".

 Shocked
Thank you.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!