[glsl] Be more null-safe for free/destroy functions

This commit is contained in:
Bill Currie 2023-03-06 18:21:13 +09:00
parent 45c0341daf
commit 488ccdc512
8 changed files with 30 additions and 4 deletions

View File

@ -46,6 +46,9 @@ ECS_NewRegistry (void)
VISIBLE void VISIBLE void
ECS_DelRegistry (ecs_registry_t *registry) ECS_DelRegistry (ecs_registry_t *registry)
{ {
if (!registry) {
return;
}
registry->locked = 1; registry->locked = 1;
for (uint32_t i = 0; i < registry->components.size; i++) { for (uint32_t i = 0; i < registry->components.size; i++) {
__auto_type comp = &registry->components.a[i]; __auto_type comp = &registry->components.a[i];

View File

@ -52,6 +52,9 @@ EntQueue_New (int num_queues)
void void
EntQueue_Delete (entqueue_t *queue) EntQueue_Delete (entqueue_t *queue)
{ {
if (!queue) {
return;
}
for (int i = 0; i < queue->num_queues; i++) { for (int i = 0; i < queue->num_queues; i++) {
DARRAY_CLEAR (&queue->ent_queues[i]); DARRAY_CLEAR (&queue->ent_queues[i]);
} }

View File

@ -83,6 +83,9 @@ dstring_new (void)
VISIBLE void VISIBLE void
dstring_delete (dstring_t *dstr) dstring_delete (dstring_t *dstr)
{ {
if (!dstr) {
return;
}
if (dstr->str) if (dstr->str)
dstr->mem->free (dstr->mem->data, dstr->str); dstr->mem->free (dstr->mem->data, dstr->str);
dstr->mem->free (dstr->mem->data, dstr); dstr->mem->free (dstr->mem->data, dstr);

View File

@ -283,6 +283,9 @@ Hash_SetHashCompare (hashtab_t *tab, uintptr_t (*gh)(const void*,void*),
VISIBLE void VISIBLE void
Hash_DelTable (hashtab_t *tab) Hash_DelTable (hashtab_t *tab)
{ {
if (!tab) {
return;
}
Hash_FlushTable (tab); Hash_FlushTable (tab);
free (tab); free (tab);
} }

View File

@ -168,6 +168,10 @@ make_glpic (const char *name, qpic_t *p)
static void static void
pic_free (qpic_t *pic) pic_free (qpic_t *pic)
{ {
if (!pic) {
return;
}
subpic_t *subpic = *(subpic_t **) pic->data; subpic_t *subpic = *(subpic_t **) pic->data;
GLSL_SubpicDelete (subpic); GLSL_SubpicDelete (subpic);

View File

@ -394,6 +394,9 @@ GLSL_ScrapClear (scrap_t *scrap)
void void
GLSL_DestroyScrap (scrap_t *scrap) GLSL_DestroyScrap (scrap_t *scrap)
{ {
if (!scrap) {
return;
}
scrap_t **s; scrap_t **s;
for (s = &scrap_list; *s; s = &(*s)->next) { for (s = &scrap_list; *s; s = &(*s)->next) {

View File

@ -65,6 +65,9 @@ R_ScrapInit (rscrap_t *scrap, int width, int height)
VISIBLE void VISIBLE void
R_ScrapDelete (rscrap_t *scrap) R_ScrapDelete (rscrap_t *scrap)
{ {
if (!scrap) {
return;
}
R_ScrapClear (scrap); R_ScrapClear (scrap);
VRect_Delete (scrap->free_rects); VRect_Delete (scrap->free_rects);
} }

View File

@ -328,11 +328,15 @@ VID_shutdown (void *data)
free (viddef.palette); free (viddef.palette);
free (viddef.palette32); free (viddef.palette32);
if (viddef.onPaletteChanged) {
DARRAY_CLEAR (viddef.onPaletteChanged); DARRAY_CLEAR (viddef.onPaletteChanged);
DARRAY_CLEAR (viddef.onVidResize);
free (viddef.onPaletteChanged); free (viddef.onPaletteChanged);
}
if (viddef.onVidResize) {
DARRAY_CLEAR (viddef.onVidResize);
free (viddef.onVidResize); free (viddef.onVidResize);
} }
}
VISIBLE void VISIBLE void
VID_Init (byte *palette, byte *colormap) VID_Init (byte *palette, byte *colormap)