Inside3D!
     

free(*ptr) problems with Windows7

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming
View previous topic :: View next topic  
Author Message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Thu Jun 24, 2010 7:36 pm    Post subject: free(*ptr) problems with Windows7 Reply with quote

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:

         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;
            }            
Back to top
View user's profile Send private message
frag.machine



Joined: 25 Nov 2006
Posts: 728

PostPosted: Thu Jun 24, 2010 8:05 pm    Post subject: Reply with quote

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.
_________________
frag.machine - Q2K4 Project
http://fragmachine.quakedev.com/
Back to top
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Thu Jun 24, 2010 8:34 pm    Post subject: Reply with quote

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.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Thu Jun 24, 2010 10:25 pm    Post subject: Reply with quote

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.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Fri Jun 25, 2010 3:42 am    Post subject: Reply with quote

Opps! was thinking they were static arrays, I guess i had revised and changed the variable declarations...
thanks to all for clarifying things Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Engine Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group