Skip to content

Commit 18e321c

Browse files
fix ownership of gif data
1 parent 1578563 commit 18e321c

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/basic/graphics.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,17 @@ bool load_into_sprite(struct basic_ctx* ctx, int64_t sprite_handle, void* buf, s
652652
s->current_frame = 0;
653653
s->loop = 1;
654654

655+
unsigned char* gif_data = buddy_malloc(ctx->allocator, size);
656+
if (!gif_data) {
657+
tokenizer_error_printf(ctx, "Not enough memory for GIF data '%s'", name);
658+
buddy_free(ctx->allocator, canvas);
659+
free_sprite(ctx, sprite_handle);
660+
return false;
661+
}
662+
memcpy(gif_data, buf, size);
663+
655664
/* Keep compressed bytes so we can rewind cheaply */
656-
s->gif_data = buf; /* ownership transferred */
665+
s->gif_data = gif_data;
657666
s->gif_size = size;
658667

659668
if (!sprite_gif_stream_reset(s)) {

0 commit comments

Comments
 (0)