Skip to content

Commit 5e3c9b8

Browse files
committed
more ZMM usage
1 parent 120554b commit 5e3c9b8

File tree

9 files changed

+46
-45
lines changed

9 files changed

+46
-45
lines changed

ext/fileinfo/libmagic/apprentice.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2847,7 +2847,7 @@ apprentice_buf(struct magic_set *ms, struct magic *buf, size_t len)
28472847
{
28482848
struct magic_map *map;
28492849

2850-
if ((map = CAST(struct magic_map *, calloc(1, sizeof(*map)))) == NULL) {
2850+
if ((map = CAST(struct magic_map *, ecalloc(1, sizeof(*map)))) == NULL) {
28512851
file_oomem(ms, sizeof(*map));
28522852
return NULL;
28532853
}

ext/fileinfo/libmagic/ascmagic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ file_ascmagic(struct magic_set *ms, const unsigned char *buf, size_t nbytes,
8989
rv = file_ascmagic_with_encoding(ms, buf, nbytes, ubuf, ulen, code,
9090
type, text);
9191

92-
free(ubuf);
92+
efree(ubuf);
9393

9494
return rv;
9595
}

ext/fileinfo/libmagic/cdf.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ cdf_zero_stream(cdf_stream_t *scn)
282282
scn->sst_len = 0;
283283
scn->sst_dirlen = 0;
284284
scn->sst_ss = 0;
285-
free(scn->sst_tab);
285+
efree(scn->sst_tab);
286286
scn->sst_tab = NULL;
287287
return -1;
288288
}
@@ -435,7 +435,7 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
435435
sat->sat_len = h->h_num_sectors_in_master_sat * nsatpersec + i;
436436
DPRINTF(("sat_len = %" SIZE_T_FORMAT "u ss = %" SIZE_T_FORMAT "u\n",
437437
sat->sat_len, ss));
438-
if ((sat->sat_tab = CAST(cdf_secid_t *, calloc(sat->sat_len, ss)))
438+
if ((sat->sat_tab = CAST(cdf_secid_t *, ecalloc(sat->sat_len, ss)))
439439
== NULL)
440440
return -1;
441441

@@ -449,7 +449,7 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
449449
}
450450
}
451451

452-
if ((msa = CAST(cdf_secid_t *, calloc(1, ss))) == NULL)
452+
if ((msa = CAST(cdf_secid_t *, ecalloc(1, ss))) == NULL)
453453
goto out1;
454454

455455
mid = h->h_secid_first_sector_in_master_sat;
@@ -484,14 +484,14 @@ cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
484484
}
485485
out:
486486
sat->sat_len = i;
487-
free(msa);
487+
efree(msa);
488488
return 0;
489489
out3:
490490
errno = EFTYPE;
491491
out2:
492-
free(msa);
492+
efree(msa);
493493
out1:
494-
free(sat->sat_tab);
494+
efree(sat->sat_tab);
495495
return -1;
496496
}
497497

@@ -547,7 +547,7 @@ cdf_read_long_sector_chain(const cdf_info_t *info, const cdf_header_t *h,
547547
if (scn->sst_len == (size_t)-1)
548548
goto out;
549549

550-
scn->sst_tab = calloc(scn->sst_len, ss);
550+
scn->sst_tab = ecalloc(scn->sst_len, ss);
551551
if (scn->sst_tab == NULL)
552552
return cdf_zero_stream(scn);
553553

@@ -593,7 +593,7 @@ cdf_read_short_sector_chain(const cdf_header_t *h,
593593
if (scn->sst_len == (size_t)-1)
594594
goto out;
595595

596-
scn->sst_tab = calloc(scn->sst_len, ss);
596+
scn->sst_tab = ecalloc(scn->sst_len, ss);
597597
if (scn->sst_tab == NULL)
598598
return cdf_zero_stream(scn);
599599

@@ -651,12 +651,12 @@ cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h,
651651

652652
dir->dir_len = ns * nd;
653653
dir->dir_tab = CAST(cdf_directory_t *,
654-
calloc(dir->dir_len, sizeof(dir->dir_tab[0])));
654+
ecalloc(dir->dir_len, sizeof(dir->dir_tab[0])));
655655
if (dir->dir_tab == NULL)
656656
return -1;
657657

658-
if ((buf = CAST(char *, malloc(ss))) == NULL) {
659-
free(dir->dir_tab);
658+
if ((buf = CAST(char *, emalloc(ss))) == NULL) {
659+
efree(dir->dir_tab);
660660
return -1;
661661
}
662662

@@ -678,11 +678,11 @@ cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h,
678678
if (NEED_SWAP)
679679
for (i = 0; i < dir->dir_len; i++)
680680
cdf_swap_dir(&dir->dir_tab[i]);
681-
free(buf);
681+
efree(buf);
682682
return 0;
683683
out:
684-
free(dir->dir_tab);
685-
free(buf);
684+
efree(dir->dir_tab);
685+
efree(buf);
686686
errno = EFTYPE;
687687
return -1;
688688
}
@@ -701,7 +701,7 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
701701
if (ssat->sat_len == (size_t)-1)
702702
goto out;
703703

704-
ssat->sat_tab = CAST(cdf_secid_t *, calloc(ssat->sat_len, ss));
704+
ssat->sat_tab = CAST(cdf_secid_t *, ecalloc(ssat->sat_len, ss));
705705
if (ssat->sat_tab == NULL)
706706
goto out1;
707707

@@ -727,7 +727,7 @@ cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h,
727727
out:
728728
errno = EFTYPE;
729729
out1:
730-
free(ssat->sat_tab);
730+
efree(ssat->sat_tab);
731731
return -1;
732732
}
733733

@@ -870,11 +870,11 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
870870
goto out;
871871
*maxcount += sh.sh_properties;
872872
inp = CAST(cdf_property_info_t *,
873-
realloc(*info, *maxcount * sizeof(*inp)));
873+
erealloc(*info, *maxcount * sizeof(*inp)));
874874
} else {
875875
*maxcount = sh.sh_properties;
876876
inp = CAST(cdf_property_info_t *,
877-
malloc(*maxcount * sizeof(*inp)));
877+
emalloc(*maxcount * sizeof(*inp)));
878878
}
879879
if (inp == NULL)
880880
goto out1;
@@ -982,7 +982,7 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
982982
goto out;
983983
*maxcount += nelements;
984984
inp = CAST(cdf_property_info_t *,
985-
realloc(*info, *maxcount * sizeof(*inp)));
985+
erealloc(*info, *maxcount * sizeof(*inp)));
986986
if (inp == NULL)
987987
goto out1;
988988
*info = inp;
@@ -1031,7 +1031,7 @@ cdf_read_property_info(const cdf_stream_t *sst, const cdf_header_t *h,
10311031
out:
10321032
errno = EFTYPE;
10331033
out1:
1034-
free(*info);
1034+
efree(*info);
10351035
return -1;
10361036
}
10371037

@@ -1098,7 +1098,7 @@ cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst,
10981098
return -1;
10991099
nr--;
11001100
*cat = CAST(cdf_catalog_t *,
1101-
malloc(sizeof(cdf_catalog_t) + nr * sizeof(*ce)));
1101+
emalloc(sizeof(cdf_catalog_t) + nr * sizeof(*ce)));
11021102
if (*cat == NULL)
11031103
return -1;
11041104
ce = (*cat)->cat_e;
@@ -1358,7 +1358,7 @@ cdf_dump_dir(const cdf_info_t *info, const cdf_header_t *h,
13581358
break;
13591359
}
13601360
cdf_dump_stream(&scn);
1361-
free(scn.sst_tab);
1361+
efree(scn.sst_tab);
13621362
break;
13631363
default:
13641364
break;
@@ -1456,7 +1456,7 @@ cdf_dump_summary_info(const cdf_header_t *h, const cdf_stream_t *sst)
14561456
(void)fprintf(stderr, "Class %s\n", buf);
14571457
(void)fprintf(stderr, "Count %d\n", ssi.si_count);
14581458
cdf_dump_property_info(info, count);
1459-
free(info);
1459+
efree(info);
14601460
}
14611461

14621462

@@ -1477,7 +1477,7 @@ cdf_dump_catalog(const cdf_header_t *h, const cdf_stream_t *sst)
14771477
cdf_u16tos8(sbuf, ce[i].ce_namlen, ce[i].ce_name),
14781478
cdf_ctime(&ts.tv_sec, tbuf));
14791479
}
1480-
free(cat);
1480+
efree(cat);
14811481
}
14821482

14831483
#endif

ext/fileinfo/libmagic/compress.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ file_zmagic(struct magic_set *ms, int fd, const char *name,
209209
goto error;
210210
if ((rbuf = file_pop_buffer(ms, pb)) != NULL) {
211211
if (file_printf(ms, "%s", rbuf) == -1) {
212-
free(rbuf);
212+
efree(rbuf);
213213
goto error;
214214
}
215-
free(rbuf);
215+
efree(rbuf);
216216
}
217217
if (!mime && file_printf(ms, ")") == -1)
218218
goto error;
@@ -452,7 +452,7 @@ uncompresszlib(const unsigned char *old, unsigned char **newch,
452452
int rc;
453453
z_stream z;
454454

455-
if ((*newch = CAST(unsigned char *, malloc(bytes_max + 1))) == NULL)
455+
if ((*newch = CAST(unsigned char *, emalloc(bytes_max + 1))) == NULL)
456456
return makeerror(newch, n, "No buffer, %s", strerror(errno));
457457

458458
z.next_in = CCAST(Bytef *, old);
@@ -669,7 +669,7 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
669669
if (fd == -1)
670670
writechild(fdp, old, *n);
671671

672-
*newch = CAST(unsigned char *, malloc(bytes_max + 1));
672+
*newch = CAST(unsigned char *, emalloc(bytes_max + 1));
673673
if (*newch == NULL) {
674674
rv = makeerror(newch, n, "No buffer, %s",
675675
strerror(errno));
@@ -688,7 +688,7 @@ uncompressbuf(int fd, size_t bytes_max, size_t method, const unsigned char *old,
688688
r = filter_error(*newch, r);
689689
break;
690690
}
691-
free(*newch);
691+
efree(*newch);
692692
if (r == 0)
693693
rv = makeerror(newch, n, "Read failed, %s",
694694
strerror(errno));

ext/fileinfo/libmagic/encoding.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
7878
*code_mime = "binary";
7979

8080
mlen = (nbytes + 1) * sizeof((*ubuf)[0]);
81-
if ((*ubuf = CAST(unichar *, calloc((size_t)1, mlen))) == NULL) {
81+
if ((*ubuf = CAST(unichar *, ecalloc((size_t)1, mlen))) == NULL) {
8282
file_oomem(ms, mlen);
8383
goto done;
8484
}
8585
mlen = (nbytes + 1) * sizeof(nbuf[0]);
86-
if ((nbuf = CAST(unsigned char *, calloc((size_t)1, mlen))) == NULL) {
86+
if ((nbuf = CAST(unsigned char *, ecalloc((size_t)1, mlen))) == NULL) {
8787
file_oomem(ms, mlen);
8888
goto done;
8989
}
@@ -143,7 +143,7 @@ file_encoding(struct magic_set *ms, const unsigned char *buf, size_t nbytes, uni
143143
}
144144

145145
done:
146-
free(nbuf);
146+
efree(nbuf);
147147

148148
return rv;
149149
}

ext/fileinfo/libmagic/funcs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ file_buffer(struct magic_set *ms, php_stream *stream, const char *inname, const
322322
#if PHP_FILEINFO_UNCOMPRESS
323323
done_encoding:
324324
#endif
325-
free(u8buf);
325+
efree(u8buf);
326326
if (rv)
327327
return rv;
328328

ext/fileinfo/libmagic/magic.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
228228
return NULL;
229229
}
230230

231+
if (file_reset(ms) == -1)
232+
goto out;
233+
231234
/*
232235
* one extra for terminating '\0', and
233236
* some overlapping space for matches near EOF
@@ -236,8 +239,6 @@ file_or_stream(struct magic_set *ms, const char *inname, php_stream *stream)
236239
if ((buf = CAST(unsigned char *, emalloc(ms->bytes_max + SLOP))) == NULL)
237240
return NULL;
238241

239-
if (file_reset(ms) == -1)
240-
goto done;
241242

242243
switch (file_fsmagic(ms, inname, &sb, stream)) {
243244
case -1: /* error */

ext/fileinfo/libmagic/print.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ file_magwarn(struct magic_set *ms, const char *f, ...)
6969
if (expanded_len >= 0 && expanded_format) {
7070
php_error_docref(NULL, E_NOTICE, "Warning: %s", expanded_format);
7171

72-
free(expanded_format);
72+
efree(expanded_format);
7373
}
7474
}
7575

ext/fileinfo/libmagic/readcdf.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
143143
const char *s;
144144
int len;
145145

146-
memset(&ts, 0, sizeof(ts));
146+
memset(&ts, 0, sizeof(ts));
147147

148148
if (!NOTMIME(ms) && root_storage)
149149
str = cdf_clsid_to_mime(root_storage->d_storage_uuid,
@@ -272,10 +272,10 @@ cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h,
272272
if (file_printf(ms, "%s%s",
273273
cdf_u16tos8(buf, ce[i].ce_namlen, ce[i].ce_name),
274274
i == cat->cat_num - 1 ? "]" : ", ") == -1) {
275-
free(cat);
275+
efree(cat);
276276
return -1;
277277
}
278-
free(cat);
278+
efree(cat);
279279
} else {
280280
if (file_printf(ms, "application/CDFV2") == -1)
281281
return -1;
@@ -336,7 +336,7 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
336336
}
337337

338338
m = cdf_file_property_info(ms, info, count, root_storage);
339-
free(info);
339+
efree(info);
340340

341341
return m == -1 ? -2 : m;
342342
}
@@ -644,11 +644,11 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
644644
cdf_zero_stream(&scn);
645645
cdf_zero_stream(&sst);
646646
out3:
647-
free(dir.dir_tab);
647+
efree(dir.dir_tab);
648648
out2:
649-
free(ssat.sat_tab);
649+
efree(ssat.sat_tab);
650650
out1:
651-
free(sat.sat_tab);
651+
efree(sat.sat_tab);
652652
out0:
653653
if (i == -1) {
654654
if (NOTMIME(ms)) {

0 commit comments

Comments
 (0)