vapour
vapour copied to clipboard
mem leak in projection info (AND VALGRIND ACCESS)
shown in valgrind output currently on CRAN, run in valgrind with
https://github.com/paleolimbot/docker-images/tree/main/r-debug#paleolimbotr-debug
apt-get update
apt-get upgrade
apt install libgdal-dev
# git clone https://github.com/hypertidy/vapour.git
#R install sysreqs and do devtools::install_dev_deps() in vapour/
remotes::install_github("r-hub/sysreqs")
# then R CMD build
# R CMD build --no-build-vignettes --no-manual vapour
#R CMD INSTALL --no-docs vapour_0.8.8.tar.gz
# R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < vapour_projection_info_cpp.R
change code in gdallibrary.h to this
// char *proj; // this gets cleaned up lower in the SRS==NULL else
List info_out(6);
CharacterVector outproj(1);
CharacterVector outnames(6);
outnames[0] = "Proj4";
outnames[1] = "MICoordSys";
outnames[2] = "PrettyWkt";
outnames[3] = "Wkt";
outnames[4] = "EPSG";
outnames[5] = "XML";
info_out.attr("names") = outnames;
if (SRS == NULL) {
//Rcpp::warning("null");
// do nothing, or warn
// e.g. .shp with no .prj
} else {
// Rcpp::warning("not null");
// SRS is not NULL, so explore validation
// OGRErr err = SRS->Validate();
char *proj4 = NULL;
SRS->exportToProj4(&proj4);
outproj[0] = proj4;
info_out[0] = Rcpp::clone(outproj);
CPLFree(proj4);
char *MI = NULL;
SRS->exportToMICoordSys(&MI);
outproj[0] = MI;
info_out[1] = Rcpp::clone(outproj);
CPLFree(MI);
char *PWKT = NULL;
SRS->exportToPrettyWkt(&PWKT, false);
outproj[0] = PWKT;
info_out[2] = Rcpp::clone(outproj);
CPLFree(PWKT);
char *UWKT = NULL;
SRS->exportToWkt(&UWKT);
outproj[0] = UWKT;
info_out[3] = Rcpp::clone(outproj);
CPLFree(UWKT);
int epsg = SRS->GetEPSGGeogCS();
info_out[4] = epsg;
char *XML = NULL;
SRS->exportToXML(&XML);
outproj[0] = XML;
info_out[5] = Rcpp::clone(outproj);
CPLFree(XML);
}
which gives
root@3df0dfb5dc32:/pkg# R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < vapour_projection_info_cpp.R
==13103== Memcheck, a memory error detector
==13103== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==13103== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==13103== Command: /usr/lib/R/bin/exec/R --vanilla
==13103==
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(vapour)
>
> file <- "list_locality_postcode_meander_valley.tab"
> ## A MapInfo TAB file with polygons
> mvfile <- system.file(file.path("extdata/tab", file), package="vapour")
> #info <- vapour_layer_info(mvfile)
> #names(info$projection)
>
> x <- vapour:::projection_info_gdal_cpp(mvfile, layer = 0L, sql = "")
>
>
>
==13103==
==13103== HEAP SUMMARY:
==13103== in use at exit: 52,855,129 bytes in 14,354 blocks
==13103== total heap usage: 91,964 allocs, 77,610 frees, 100,017,874 bytes allocated
==13103==
==13103== LEAK SUMMARY:
==13103== definitely lost: 0 bytes in 0 blocks
==13103== indirectly lost: 0 bytes in 0 blocks
==13103== possibly lost: 0 bytes in 0 blocks
==13103== still reachable: 52,855,129 bytes in 14,354 blocks
==13103== of which reachable via heuristic:
==13103== newarray : 4,264 bytes in 1 blocks
==13103== suppressed: 0 bytes in 0 blocks
==13103== Reachable blocks (those to which a pointer was found) are not shown.
==13103== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==13103==
==13103== For lists of detected and suppressed errors, rerun with: -s
==13103== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
now we have
==17764==
==17764== HEAP SUMMARY:
==17764== in use at exit: 64,403,898 bytes in 18,899 blocks
==17764== total heap usage: 252,125 allocs, 233,226 frees, 900,894,254 bytes allocated
==17764==
==17764== 46 bytes in 1 blocks are definitely lost in loss record 3,069 of 6,271
==17764== at 0x483F7B5: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==17764== by 0x11A055611: CPLMalloc (in /usr/lib/libgdal.so.30.0.2)
==17764== by 0x11A05570C: CPLStrdup (in /usr/lib/libgdal.so.30.0.2)
==17764== by 0x119377522: OGRSpatialReference::exportToProj4(char**) const (in /usr/lib/libgdal.so.30.0.2)
==17764== by 0x57F4EA67: gdallibrary::gdal_raster_info(Rcpp::Vector<16, Rcpp::PreserveStorage>, Rcpp::Vector<10, Rcpp::PreserveStorage>) (gdallibrary.h:1083)
==17764== by 0x57F4CC83: raster_info_gdal_cpp(Rcpp::Vector<16, Rcpp::PreserveStorage>, Rcpp::Vector<10, Rcpp::PreserveStorage>) (00_raster.cpp:14)
==17764== by 0x57F66D45: _vapour_raster_info_gdal_cpp (RcppExports.cpp:449)
==17764== by 0x494E42B: ??? (in /usr/lib/R/lib/libR.so)
==17764== by 0x494E9BC: ??? (in /usr/lib/R/lib/libR.so)
==17764== by 0x4987944: ??? (in /usr/lib/R/lib/libR.so)
==17764== by 0x49A495F: Rf_eval (in /usr/lib/R/lib/libR.so)
==17764== by 0x49A64DE: ??? (in /usr/lib/R/lib/libR.so)
==17764==
==17764== LEAK SUMMARY:
==17764== definitely lost: 46 bytes in 1 blocks
==17764== indirectly lost: 0 bytes in 0 blocks
==17764== possibly lost: 0 bytes in 0 blocks
==17764== still reachable: 64,403,852 bytes in 18,898 blocks
==17764== of which reachable via heuristic:
==17764== newarray : 4,264 bytes in 1 blocks
==17764== suppressed: 0 bytes in 0 blocks
==17764== Reachable blocks (those to which a pointer was found) are not shown.
now fixed