Do memory checks

Slightly improve memory cleanup in Pl_DCT
Make it easier to test with valgrind
This commit is contained in:
Jay Berkenbilt 2017-08-22 10:51:21 -04:00
parent 85ef2cb6fd
commit 83ec09f66c
5 changed files with 65 additions and 27 deletions

View File

@ -21,34 +21,19 @@ Release Reminders
LDFLAGS="-fsanitize=address" \ LDFLAGS="-fsanitize=address" \
--enable-werror --disable-shared --enable-werror --disable-shared
* Consider running tests with latest gcc and/or valgrind. To do As of gcc 6.3.0, this exposes some good things but appears to also
this, replace, build with debugging and without shared libraries. have some false positive leak reports. Valgrind is more reliable
In build, create z and move each executable into z. Then create a but also may miss some things that this catches.
script called exec-z that contains:
#!/bin/sh * Consider running tests with latest gcc and/or valgrind. To test
exec valgrind --suppressions=/tmp/a.supp -q \ with valgrind:
`dirname $0`/z/`basename $0` ${1+"$@"}
Symlink exec-z to each executable. /tmp/a.supp can be populated ./configure --disable-shared
with suppressions for libraries, for example: make -j8 -k VALGRIND=1
make -k check NO_REBUILD=1
{ This moves each binary into a subdirectory and replaces it with a
zlib1 link to make/exec-z. See make/exec-z.
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.
* Check all open issues in the sourceforge trackers and on github. * Check all open issues in the sourceforge trackers and on github.

View File

@ -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 void
Pl_DCT::compress(void* cinfo_p, PointerHolder<Buffer> b) Pl_DCT::compress(void* cinfo_p, PointerHolder<Buffer> b)
{ {
@ -124,6 +143,7 @@ Pl_DCT::compress(void* cinfo_p, PointerHolder<Buffer> b)
# pragma GCC diagnostic pop # pragma GCC diagnostic pop
#endif #endif
unsigned char* outbuffer = 0; unsigned char* outbuffer = 0;
Freer freer(&outbuffer);
unsigned long outsize = 0; unsigned long outsize = 0;
jpeg_mem_dest(cinfo, &outbuffer, &outsize); jpeg_mem_dest(cinfo, &outbuffer, &outsize);
@ -160,8 +180,6 @@ Pl_DCT::compress(void* cinfo_p, PointerHolder<Buffer> b)
jpeg_finish_compress(cinfo); jpeg_finish_compress(cinfo);
this->getNext()->write(outbuffer, outsize); this->getNext()->write(outbuffer, outsize);
this->getNext()->finish(); this->getNext()->finish();
free(outbuffer);
} }
void void

24
make/exec-z Executable file
View File

@ -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 <<EOF
{
zlib1
Memcheck:Cond
fun:inflateReset2
fun:inflateInit2_
}
{
index
Memcheck:Cond
fun:index
fun:expand_dynamic_string_token
fun:_dl_map_object
fun:map_doit
}
EOF
exec valgrind --suppressions=/tmp/a.supp -q \
`dirname $0`/z/`basename $0` ${1+"$@"}

View File

@ -102,6 +102,7 @@ endef
# Usage: $(call makebin,objs,binary,ldflags,libs) # Usage: $(call makebin,objs,binary,ldflags,libs)
define makebin define makebin
$(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(1) -o $(2) $(4) $(3) $(LIBTOOL) --mode=link $(CXX) $(CXXFLAGS) $(1) -o $(2) $(4) $(3)
if [ "$(VALGRIND)" = 1 ]; then make/valgrind-wrap $(2); fi
endef endef
# Install target # Install target

10
make/valgrind-wrap Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
set -e
pwd
dir=$(dirname $1)
if [ ! -x $dir/exec-z ]; then
ln -f make/exec-z $dir/exec-z
fi
mkdir -p $dir/z
mv $1 $dir/z
ln -f $dir/exec-z $1