Skip to content

Commit

Permalink
Clarify that mspack_system.free() should accept and ignore NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
kyz committed Aug 13, 2018
1 parent 846db1c commit c27ea1a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
8 changes: 8 additions & 0 deletions libmspack/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2018-08-13 Stuart Caie <kyzer@cabextract.org.uk>

* mspack.h: clarify that mspack_system.free() should allow NULL. If your
mspack_system implementation doesn't, it would already have crashed, as
there are several places where libmspack calls sys->free(NULL). This
change makes it official, and amends a few "if (x) sys->free(x)" cases
to the simpler "sys->free(x)" to make it clearer.

2018-08-09 Stuart Caie <kyzer@cabextract.org.uk>

* Makefile.am: the test file cve-2015-4467-reset-interval-zero.chm is
Expand Down
4 changes: 2 additions & 2 deletions libmspack/mspack/kwajd.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ static struct mskwajd_header *kwajd_open(struct mskwaj_decompressor *base,
}

if (self->error) {
if (fh) sys->close(fh);
if (hdr) sys->free(hdr);
if (fh) sys->close(fh);
sys->free(hdr);
hdr = NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion libmspack/mspack/mspack.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ struct mspack_system {
/**
* Frees memory.
*
* @param ptr the memory to be freed.
* @param ptr the memory to be freed. NULL is accepted and ignored.
* @see alloc()
*/
void (*free)(void *ptr);
Expand Down
27 changes: 9 additions & 18 deletions libmspack/mspack/oabd.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,10 @@ static int oabd_decompress(struct msoab_decompressor *_self, const char *input,
}

out:
if (lzx)
lzxd_free(lzx);
if (buf)
sys->free(buf);
if (outfh)
sys->close(outfh);
if (infh)
sys->close(infh);
if (lzx) lzxd_free(lzx);
if (outfh) sys->close(outfh);
if (infh) sys->close(infh);
sys->free(buf);

return ret;
}
Expand Down Expand Up @@ -390,16 +386,11 @@ static int oabd_decompress_incremental(struct msoab_decompressor *_self,
}

out:
if (lzx)
lzxd_free(lzx);
if (buf)
sys->free(buf);
if (outfh)
sys->close(outfh);
if (basefh)
sys->close(basefh);
if (infh)
sys->close(infh);
if (lzx) lzxd_free(lzx);
if (outfh) sys->close(outfh);
if (basefh) sys->close(basefh);
if (infh) sys->close(infh);
sys->free(buf);

return ret;
}
4 changes: 2 additions & 2 deletions libmspack/mspack/szddd.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ static struct msszddd_header *szddd_open(struct msszdd_decompressor *base,
}

if (self->error) {
if (fh) sys->close(fh);
if (hdr) sys->free(hdr);
if (fh) sys->close(fh);
sys->free(hdr);
hdr = NULL;
}

Expand Down

0 comments on commit c27ea1a

Please sign in to comment.