Open am2222 opened 7 years ago
Hi, valgrind should be able to detect memory leaks in dynamically loaded plugins. I have tried it now by creating a memory leak in GDAL plugin.
If there is some system limitation in using valgrind with dynamically loaded libraries, it should be possible to statically link all plugins by PLUGIN_LINKING
.
@talaj Thanks for your help, Can you please explain its procedure? for example in GDAL plugin?
I make a memory leak:
diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp
index 1ac6557fe..9cc11878b 100644
--- a/plugins/input/gdal/gdal_datasource.cpp
+++ b/plugins/input/gdal/gdal_datasource.cpp
@@ -61,6 +61,7 @@ gdal_datasource::gdal_datasource(parameters const& params)
nodata_value_(params.get<double>("nodata")),
nodata_tolerance_(*params.get<double>("nodata_tolerance",1e-12))
{
+ new char[123];
MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Initializing...";
#ifdef MAPNIK_STATS
Complile Mapnik from sources. When compiled, I use the visual test runner test/visual/run
to run Mapnik against this style.
$ valgrind test/visual/run --agg -s 1 raster-color-to-alpha1
==16387== Memcheck, a memory error detector
==16387== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==16387== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==16387== Command: test/visual/run --agg -s 1 raster-color-to-alpha1
==16387==
.
Visual rendering: 0 failed / 1 passed / 0 overwritten / 0 errors
==16387==
==16387== HEAP SUMMARY:
==16387== in use at exit: 178,819 bytes in 413 blocks
==16387== total heap usage: 22,056 allocs, 21,643 frees, 7,643,454 bytes allocated
==16387==
==16387== LEAK SUMMARY:
==16387== definitely lost: 123 bytes in 1 blocks
==16387== indirectly lost: 0 bytes in 0 blocks
==16387== possibly lost: 0 bytes in 0 blocks
==16387== still reachable: 178,696 bytes in 412 blocks
==16387== suppressed: 0 bytes in 0 blocks
==16387== Rerun with --leak-check=full to see details of leaked memory
==16387==
==16387== For counts of detected and suppressed errors, rerun with: -v
==16387== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
But you don't have to build Mapnik yourself. Just run your program through valgrind.
@talaj thanks for your help,I'll check it and report the results .thanks
If you have memory leaks with Mapnik and GDAL, check your GDAL version. I have fixed leaks with GDAL version 1.x by upgrading to GDAL 2.x.
@am2222 Concerning GDAL memory usage it is also good to know that libtiff allocates memory for tile or strip positions and lengths. Having TIFF with 4000 x 4000 tiles will take 256 MB of memory.
@talaj thanks for your information, I noticed a grind option in mapnik build system, Does it have any relations to valgrind tests?
There is grind
target in the makefile which should run valgrind on Mapnik's tests but I don't know if anyone is using it. It doesn't work for me neither.
@talaj yes it did not work for me too. I have no idea about its usage, thanks very much.
Hi, It is for a while that I am working with mapnik, one of my problems is how to integrate valgrind test for memory leak analyses into mapnik input plugins. As far as I am concerned I have to integrate valgrind into scons system, for example in gdal plugin a dependency is deffined in PLUGINS variable in sconstract file should I add valgrinds headers too? thanks