Merge pull request #1148 from 0lvin/backport

Fix memory leaks
This commit is contained in:
Yamagi 2024-09-08 09:33:53 +02:00 committed by GitHub
commit 14f819aac5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 67 additions and 27 deletions

View file

@ -54,7 +54,8 @@ CL_AddMuzzleFlash(void)
if ((i < 1) || (i >= MAX_EDICTS)) if ((i < 1) || (i >= MAX_EDICTS))
{ {
Com_Error(ERR_DROP, "CL_AddMuzzleFlash: bad entity"); Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, i, MAX_EDICTS);
} }
weapon = MSG_ReadByte(&net_message); weapon = MSG_ReadByte(&net_message);
@ -334,14 +335,15 @@ CL_AddMuzzleFlash2(void)
if ((ent < 1) || (ent >= MAX_EDICTS)) if ((ent < 1) || (ent >= MAX_EDICTS))
{ {
Com_Error(ERR_DROP, "CL_AddMuzzleFlash2: bad entity"); Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, ent, MAX_EDICTS);
} }
flash_number = MSG_ReadByte(&net_message); flash_number = MSG_ReadByte(&net_message);
if (flash_number > 210) if (flash_number > 210)
{ {
Com_DPrintf("CL_AddMuzzleFlash2: bad offset"); Com_DPrintf("%s: bad offset\n", __func__);
return; return;
} }

View file

@ -864,7 +864,8 @@ CL_GetEntitySoundOrigin(int ent, vec3_t org)
if ((ent < 0) || (ent >= MAX_EDICTS)) if ((ent < 0) || (ent >= MAX_EDICTS))
{ {
Com_Error(ERR_DROP, "CL_GetEntitySoundOrigin: bad ent"); Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, ent, MAX_EDICTS);
} }
old = &cl_entities[ent]; old = &cl_entities[ent];
@ -881,7 +882,8 @@ CL_GetEntitySoundVelocity(int ent, vec3_t vel)
if ((ent < 0) || (ent >= MAX_EDICTS)) if ((ent < 0) || (ent >= MAX_EDICTS))
{ {
Com_Error(ERR_DROP, "CL_GetEntitySoundVelocity: bad ent"); Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, ent, MAX_EDICTS);
} }
old = &cl_entities[ent]; old = &cl_entities[ent];

View file

@ -265,9 +265,15 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
return; return;
} }
if ((len > 768) && (((byte *)pcx)[len - 769] == 0x0C)) if (len > 768)
{ {
memcpy(*palette, (byte *)pcx + len - 768, 768); memcpy(*palette, (byte *)pcx + len - 768, 768);
if ((((byte *)pcx)[len - 769] != 0x0C))
{
Com_DPrintf("%s: %s has no palette marker\n",
__func__, name);
}
} }
else else
{ {

View file

@ -380,12 +380,13 @@ CL_ParsePacketEntities(frame_t *oldframe, frame_t *newframe)
if (newnum >= MAX_EDICTS) if (newnum >= MAX_EDICTS)
{ {
Com_Error(ERR_DROP, "CL_ParsePacketEntities: bad number:%i", newnum); Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, newnum, MAX_EDICTS);
} }
if (net_message.readcount > net_message.cursize) if (net_message.readcount > net_message.cursize)
{ {
Com_Error(ERR_DROP, "CL_ParsePacketEntities: end of message"); Com_Error(ERR_DROP, "%s: end of message", __func__);
} }
if (!newnum) if (!newnum)
@ -1192,7 +1193,8 @@ CL_ParseStartSoundPacket(void)
if (ent > MAX_EDICTS) if (ent > MAX_EDICTS)
{ {
Com_Error(ERR_DROP, "CL_ParseStartSoundPacket: ent = %i", ent); Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, ent, MAX_EDICTS);
} }
channel &= 7; channel &= 7;

View file

@ -5695,11 +5695,19 @@ HasSkinsInDir(const char *dirname, int *num)
for (j = 0; j < num_png; j ++) for (j = 0; j < num_png; j ++)
{ {
if (list_png[j] && !strchr(list_png[j] + dirname_size, '/')) if (list_png[j])
{
if (!strchr(list_png[j] + dirname_size, '/'))
{ {
*curr = list_png[j]; *curr = list_png[j];
curr++; curr++;
} }
else
{
/* unused in final response */
free(list_png[j]);
}
}
} }
free(list_png); free(list_png);
@ -5711,11 +5719,19 @@ HasSkinsInDir(const char *dirname, int *num)
for (j = 0; j < num_pcx; j ++) for (j = 0; j < num_pcx; j ++)
{ {
if (list_pcx[j] && !strchr(list_pcx[j] + dirname_size, '/')) if (list_pcx[j])
{
if (!strchr(list_pcx[j] + dirname_size, '/'))
{ {
*curr = list_pcx[j]; *curr = list_pcx[j];
curr++; curr++;
} }
else
{
/* unused in final response */
free(list_pcx[j]);
}
}
} }
free(list_pcx); free(list_pcx);

View file

@ -340,9 +340,15 @@ PCX_Decode(const char *name, const byte *raw, int len, byte **pic, byte **palett
return; return;
} }
if ((len > 768) && (((byte *)pcx)[len - 769] == 0x0C)) if (len > 768)
{ {
memcpy(*palette, (byte *)pcx + len - 768, 768); memcpy(*palette, (byte *)pcx + len - 768, 768);
if ((((byte *)pcx)[len - 769] != 0x0C))
{
R_Printf(PRINT_DEVELOPER, "%s: %s has no palette marker\n",
__func__, name);
}
} }
else else
{ {

View file

@ -109,8 +109,7 @@ LM_UploadBlock(qboolean dynamic)
} }
else else
{ {
gl_lms.internal_format = GL_LIGHTMAP_FORMAT; glTexImage2D(GL_TEXTURE_2D, 0, GL_LIGHTMAP_FORMAT,
glTexImage2D(GL_TEXTURE_2D, 0, gl_lms.internal_format,
gl_state.block_width, gl_state.block_height, gl_state.block_width, gl_state.block_height,
0, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, 0, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE,
gl_lms.lightmap_buffer[buffer]); gl_lms.lightmap_buffer[buffer]);
@ -123,7 +122,7 @@ LM_UploadBlock(qboolean dynamic)
R_Bind(gl_state.lightmap_textures + (gl_state.max_lightmaps * i) + texture); R_Bind(gl_state.lightmap_textures + (gl_state.max_lightmaps * i) + texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, gl_lms.internal_format, glTexImage2D(GL_TEXTURE_2D, 0, GL_LIGHTMAP_FORMAT,
gl_state.block_width, gl_state.block_height, gl_state.block_width, gl_state.block_height,
0, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, 0, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE,
gl_lms.lightmap_buffer[buffer]); gl_lms.lightmap_buffer[buffer]);
@ -326,7 +325,6 @@ LM_BeginBuildingLightmaps(model_t *m)
} }
gl_lms.current_lightmap_texture = 1; gl_lms.current_lightmap_texture = 1;
gl_lms.internal_format = GL_LIGHTMAP_FORMAT;
if (gl_config.multitexture) if (gl_config.multitexture)
{ {
@ -341,7 +339,7 @@ LM_BeginBuildingLightmaps(model_t *m)
R_Bind(gl_state.lightmap_textures + 0); R_Bind(gl_state.lightmap_textures + 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, gl_lms.internal_format, glTexImage2D(GL_TEXTURE_2D, 0, GL_LIGHTMAP_FORMAT,
gl_state.block_width, gl_state.block_height, gl_state.block_width, gl_state.block_height,
0, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE, 0, GL_LIGHTMAP_FORMAT, GL_UNSIGNED_BYTE,
gl_lms.lightmap_buffer[0]); gl_lms.lightmap_buffer[0]);

View file

@ -463,7 +463,6 @@ typedef struct
typedef struct typedef struct
{ {
int internal_format;
int current_lightmap_texture; int current_lightmap_texture;
msurface_t *lightmap_surfaces[MAX_LIGHTMAPS]; msurface_t *lightmap_surfaces[MAX_LIGHTMAPS];

View file

@ -56,8 +56,7 @@ GL3_LM_UploadBlock(void)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gl3_lms.internal_format = GL_LIGHTMAP_FORMAT; glTexImage2D(GL_TEXTURE_2D, 0, GL_LIGHTMAP_FORMAT,
glTexImage2D(GL_TEXTURE_2D, 0, gl3_lms.internal_format,
BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_LIGHTMAP_FORMAT, BLOCK_WIDTH, BLOCK_HEIGHT, 0, GL_LIGHTMAP_FORMAT,
GL_UNSIGNED_BYTE, gl3_lms.lightmap_buffers[map]); GL_UNSIGNED_BYTE, gl3_lms.lightmap_buffers[map]);
} }
@ -255,7 +254,6 @@ GL3_LM_BeginBuildingLightmaps(gl3model_t *m)
gl3_newrefdef.lightstyles = lightstyles; gl3_newrefdef.lightstyles = lightstyles;
gl3_lms.current_lightmap_texture = 0; gl3_lms.current_lightmap_texture = 0;
gl3_lms.internal_format = GL_LIGHTMAP_FORMAT;
// Note: the dynamic lightmap used to be initialized here, we don't use that anymore. // Note: the dynamic lightmap used to be initialized here, we don't use that anymore.
} }

View file

@ -317,7 +317,6 @@ enum {MAX_GL3TEXTURES = 1024};
typedef struct typedef struct
{ {
int internal_format;
int current_lightmap_texture; // index into gl3state.lightmap_textureIDs[] int current_lightmap_texture; // index into gl3state.lightmap_textureIDs[]
//msurface_t *lightmap_surfaces[MAX_LIGHTMAPS]; - no more lightmap chains, lightmaps are rendered multitextured //msurface_t *lightmap_surfaces[MAX_LIGHTMAPS]; - no more lightmap chains, lightmaps are rendered multitextured

View file

@ -731,6 +731,12 @@ FS_LoadFile(const char *path, void **buffer)
if (size <= 0) if (size <= 0)
{ {
if (size == 0)
{
/* empty file, close before exit*/
FS_FCloseFile(f);
}
if (buffer) if (buffer)
{ {
*buffer = NULL; *buffer = NULL;

View file

@ -444,7 +444,8 @@ MSG_WriteDeltaEntity(entity_state_t *from,
if (to->number >= MAX_EDICTS) if (to->number >= MAX_EDICTS)
{ {
Com_Error(ERR_FATAL, "Entity number >= MAX_EDICTS"); Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, to->number, MAX_EDICTS);
} }
/* send an update */ /* send an update */

View file

@ -122,6 +122,11 @@ SV_CreateBaseline(void)
/* take current state as baseline */ /* take current state as baseline */
VectorCopy(svent->s.origin, svent->s.old_origin); VectorCopy(svent->s.origin, svent->s.old_origin);
if (entnum >= MAX_EDICTS)
{
Com_Error(ERR_DROP, "%s: bad entity %d >= %d\n",
__func__, entnum, MAX_EDICTS);
}
sv.baselines[entnum] = svent->s; sv.baselines[entnum] = svent->s;
} }
} }