Forum

free(*ptr) problems with Windows7

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

free(*ptr) problems with Windows7

Postby r00k » Thu Jun 24, 2010 7:36 pm

Windows 7 keeps crashing if i use free(ptr) in some instances where in Win XP it doesnt

here's what i have replaced free with that works on both OS's but not sure if it's proper to use memset instead of free?

Code: Select all
         if ((cls.download.error)||(success == FALSE))
            {
               Con_Printf ("Download Error: %s\n",cls.download.error);
               Con_Printf ("\nThe required file '%s' could not be found at %s.\n", model_precache[i], url);
               remove (download_tempname);
               memset (download_tempname, 0, sizeof(download_tempname));
               memset (download_finalname, 0, sizeof(download_finalname));
               memset (url, 0, sizeof(url));
               memset (name, 0, sizeof(name));
               memset (folder, 0, sizeof(folder));
               return;
            }            
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby frag.machine » Thu Jun 24, 2010 8:05 pm

memset () doesn't free the pointer, you're just clearing the memory it points - and not in a very legible way, since we cannot infer how much of the heap the variables passed as arguments to sizeof() are using.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm

Postby Spike » Thu Jun 24, 2010 8:34 pm

memory allocated with malloc must be freed within the same module that malloced it.
Failing that, you must ensure that the version of the CRT matches exactly.
Which it probably doesn't.
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby mh » Thu Jun 24, 2010 10:25 pm

From looking at your code, you've got char download_tempname[MAX_QPATH] at the start of your loop. There's no need to free a static array, so the Windows 7 behaviour is actually correct, if a little less forgiving.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby r00k » Fri Jun 25, 2010 3:42 am

Opps! was thinking they were static arrays, I guess i had revised and changed the variable declarations...
thanks to all for clarifying things :)
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest