fixed memory issues Alam running valgrind found

This commit is contained in:
Inuyasha 2016-05-08 20:34:43 -07:00
parent 987f65fde8
commit a9be5ba867
2 changed files with 13 additions and 13 deletions

View file

@ -625,11 +625,11 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture)
char *texturesToken; char *texturesToken;
UINT8 texturesTokenLength; UINT8 texturesTokenLength;
char *endPos; char *endPos;
char *newTextureName = NULL;
INT32 newTextureWidth; INT32 newTextureWidth;
INT32 newTextureHeight; INT32 newTextureHeight;
texture_t *resultTexture = NULL; texture_t *resultTexture = NULL;
texpatch_t *newPatch; texpatch_t *newPatch;
char newTextureName[9]; // no longer dynamically allocated
// Texture name // Texture name
texturesToken = M_GetToken(NULL); texturesToken = M_GetToken(NULL);
@ -644,13 +644,10 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture)
} }
else else
{ {
if (newTextureName != NULL) memset(&newTextureName, 0, 9);
{ M_Memcpy(newTextureName, texturesToken, texturesTokenLength);
Z_Free(newTextureName); // ^^ we've confirmed that the token is <= 8 characters so it will never overflow a 9 byte char buffer
} strupr(newTextureName); // Just do this now so we don't have to worry about it
newTextureName = (char *)Z_Malloc((texturesTokenLength+1)*sizeof(char),PU_STATIC,NULL);
M_Memcpy(newTextureName,texturesToken,texturesTokenLength*sizeof(char));
newTextureName[texturesTokenLength] = '\0';
} }
Z_Free(texturesToken); Z_Free(texturesToken);
@ -734,7 +731,6 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture)
{ {
// Allocate memory for a zero-patch texture. Obviously, we'll be adding patches momentarily. // Allocate memory for a zero-patch texture. Obviously, we'll be adding patches momentarily.
resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t),PU_STATIC,NULL); resultTexture = (texture_t *)Z_Calloc(sizeof(texture_t),PU_STATIC,NULL);
strupr(newTextureName);
M_Memcpy(resultTexture->name, newTextureName, 8); M_Memcpy(resultTexture->name, newTextureName, 8);
resultTexture->width = newTextureWidth; resultTexture->width = newTextureWidth;
resultTexture->height = newTextureHeight; resultTexture->height = newTextureHeight;
@ -790,7 +786,6 @@ static texture_t *R_ParseTexture(boolean actuallyLoadTexture)
} }
Z_Free(texturesToken); Z_Free(texturesToken);
Z_Free(newTextureName); // Can't BELIEVE I forgot to free this before ._.;
if (actuallyLoadTexture) return resultTexture; if (actuallyLoadTexture) return resultTexture;
else return NULL; else return NULL;
} }

View file

@ -1696,9 +1696,14 @@ void I_StartupGraphics(void)
} }
#endif #endif
{ {
char vd[100]; //stack space for video name const char *vd = SDL_GetCurrentVideoDriver();
//CONS_Printf(M_GetText("Starting up with video driver : %s\n"), SDL_VideoDriverName(vd,100)); //CONS_Printf(M_GetText("Starting up with video driver: %s\n"), vd);
if (strncasecmp(vd, "gcvideo", 8) == 0 || strncasecmp(vd, "fbcon", 6) == 0 || strncasecmp(vd, "wii", 4) == 0 || strncasecmp(vd, "psl1ght", 8) == 0) if (vd && (
strncasecmp(vd, "gcvideo", 8) == 0 ||
strncasecmp(vd, "fbcon", 6) == 0 ||
strncasecmp(vd, "wii", 4) == 0 ||
strncasecmp(vd, "psl1ght", 8) == 0
))
framebuffer = SDL_TRUE; framebuffer = SDL_TRUE;
} }
if (M_CheckParm("-software")) if (M_CheckParm("-software"))