diff --git a/README.maintainer b/README.maintainer index f4021f3d..e6027447 100644 --- a/README.maintainer +++ b/README.maintainer @@ -21,34 +21,19 @@ Release Reminders LDFLAGS="-fsanitize=address" \ --enable-werror --disable-shared - * Consider running tests with latest gcc and/or valgrind. To do - this, replace, build with debugging and without shared libraries. - In build, create z and move each executable into z. Then create a - script called exec-z that contains: + As of gcc 6.3.0, this exposes some good things but appears to also + have some false positive leak reports. Valgrind is more reliable + but also may miss some things that this catches. - #!/bin/sh - exec valgrind --suppressions=/tmp/a.supp -q \ - `dirname $0`/z/`basename $0` ${1+"$@"} + * Consider running tests with latest gcc and/or valgrind. To test + with valgrind: - Symlink exec-z to each executable. /tmp/a.supp can be populated - with suppressions for libraries, for example: + ./configure --disable-shared + make -j8 -k VALGRIND=1 + make -k check NO_REBUILD=1 - { - zlib1 - Memcheck:Cond - fun:inflateReset2 - fun:inflateInit2_ - } - { - index - Memcheck:Cond - fun:index - fun:expand_dynamic_string_token - fun:_dl_map_object - fun:map_doit - } - - You can generate these by running valgrind with --gen-suppressions=yes. + This moves each binary into a subdirectory and replaces it with a + link to make/exec-z. See make/exec-z. * Check all open issues in the sourceforge trackers and on github. diff --git a/libqpdf/Pl_DCT.cc b/libqpdf/Pl_DCT.cc index 68cdc973..121ee273 100644 --- a/libqpdf/Pl_DCT.cc +++ b/libqpdf/Pl_DCT.cc @@ -107,6 +107,25 @@ Pl_DCT::finish() } } +class Freer +{ + public: + Freer(unsigned char** p) : + p(p) + { + } + ~Freer() + { + if (*p) + { + free(*p); + } + } + + private: + unsigned char** p; +}; + void Pl_DCT::compress(void* cinfo_p, PointerHolder b) { @@ -124,6 +143,7 @@ Pl_DCT::compress(void* cinfo_p, PointerHolder b) # pragma GCC diagnostic pop #endif unsigned char* outbuffer = 0; + Freer freer(&outbuffer); unsigned long outsize = 0; jpeg_mem_dest(cinfo, &outbuffer, &outsize); @@ -160,8 +180,6 @@ Pl_DCT::compress(void* cinfo_p, PointerHolder b) jpeg_finish_compress(cinfo); this->getNext()->write(outbuffer, outsize); this->getNext()->finish(); - - free(outbuffer); } void diff --git a/make/exec-z b/make/exec-z new file mode 100755 index 00000000..dc21dbc1 --- /dev/null +++ b/make/exec-z @@ -0,0 +1,24 @@ +#!/bin/sh +# This script is used for valgrind testing. See README.maintainer. + +# Create a suppressions file. This can be updated by running valgrind +# with --gen-suppressions=yes. +test -f /tmp/a.supp || cat > /tmp/a.supp <