@@ -19,25 +19,38 @@ STBIDEF unsigned char *stbi__xload_main(stbi__context *s, int *x, int *y, int *f
19
19
gif_result head ;
20
20
gif_result * prev = 0 , * gr = & head ;
21
21
22
+ int stride = 0 ;
23
+ unsigned char * temp = 0 ;
22
24
memset (& g , 0 , sizeof (g ));
23
25
memset (& head , 0 , sizeof (head ));
24
26
25
27
* frames = 0 ;
26
28
27
- while ((gr -> data = stbi__gif_load_next (s , & g , channels , 4 ))) {
29
+ while ((gr -> data = stbi__gif_load_next (s , & g , channels , 4 , 0 ))) {
28
30
if (gr -> data == (unsigned char * )s ) {
29
31
gr -> data = 0 ;
30
32
break ;
31
33
}
32
34
33
35
if (prev ) prev -> next = gr ;
34
- gr -> delay = g .delay ;
36
+ gr -> delay = g .delay / 10 ; // the delay has been saved as 1/1000 s in the new stb_image.h
35
37
prev = gr ;
36
38
gr = (gif_result * ) stbi__malloc (sizeof (gif_result ));
37
39
memset (gr , 0 , sizeof (gif_result ));
38
40
++ (* frames );
41
+
42
+ {
43
+ stride = 4 * g .w * g .h ;
44
+ temp = prev -> data ;
45
+ prev -> data = (unsigned char * )stbi__malloc (stride );
46
+ memcpy (prev -> data , temp , stride );
47
+ }
39
48
}
40
49
50
+ STBI_FREE (g .out );
51
+ STBI_FREE (g .history );
52
+ STBI_FREE (g .background );
53
+
41
54
if (gr != & head )
42
55
STBI_FREE (gr );
43
56
@@ -69,7 +82,8 @@ STBIDEF unsigned char *stbi__xload_main(stbi__context *s, int *x, int *y, int *f
69
82
}
70
83
}
71
84
} else {
72
- result = stbi__load_main (s , x , y , channels , 0 );
85
+ stbi__result_info ri ;
86
+ result = stbi__load_main (s , x , y , channels , 0 , & ri , 8 );
73
87
* frames = !!result ;
74
88
}
75
89
@@ -142,7 +156,7 @@ void img_load_from_data(image_t *img, stbi_uc* ptr, int w, int h, int frames, in
142
156
exit (1 );
143
157
}
144
158
145
- if (frames > 1 && !(img -> delays = malloc (sizeof (uint16_t ) * (frames - 1 )))) {
159
+ if (frames > 1 && !(img -> delays = malloc (sizeof (uint16_t ) * (frames )))) { // avoid buffer overflow
146
160
perror ("malloc error\n" );
147
161
exit (1 );
148
162
}
@@ -243,6 +257,9 @@ void img_convert_colors(image_t *img)
243
257
void img_free (image_t * img )
244
258
{
245
259
free (img -> pixels );
260
+ if (img -> delays ) {
261
+ free (img -> delays );
262
+ }
246
263
}
247
264
248
265
void img_resize (image_t * img , float wsc , float hsc )
0 commit comments