<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, EmojiFont, "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p>Thanks Even and Greg for your fast replies</p>
<p><br>
</p>
<p>The app and GDAL are built with Android NDK 21 (I have tried NDK 30 and 31) and is targeting SDK 30. High memory Android device is 10Gb or even 14Gb with RAM PLUS. I can add that the app itself is based on Qt 5.15.8 and runs fine on Windows, Linux, Raspberry
 2/3/4 32bits or 64bits, MacOS, iOS and Android without Scudo. It is heavily multithreaded including during GDAL calls.</p>
<p><br>
</p>
<p>I can also add that I have tried a 32bits build (armv7) running on these armV8 devices, same problem, although the messages in logcat are a bit different. I can also say that I am 99.9% sure this is triggered by GDAL, because our same exactly S52/57 module reading
 other formats without GDAL does not crash.</p>
<p><br>
</p>
<p>I have seen these debug defines in cpl_simple.cpp. I will enable them, rebuild and report here. I don't have a scudo device apart from a emulated one but it is x86-64 and it does not seem to behave exactly the same as the users' ARM64 bits (Samsung S21).
 My feeling is that it is connected to ARM 64 architecture.</p>
<p><br>
</p>
<p>Thanks again, more later hopefully.</p>
<p>Philippe.</p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Even Rouault <even.rouault@spatialys.com><br>
<b>Sent:</b> Monday, March 28, 2022 3:24 PM<br>
<b>To:</b> Philippe Lelong; gdal-dev@lists.osgeo.org<br>
<b>Subject:</b> Re: [gdal-dev] Memory allocation issues on Android 11+ and scudo</font>
<div> </div>
</div>
<div>
<p>Hi,</p>
<p>didn't hear about Scudo before, but it seems it is a LLVM side project: <a class="moz-txt-link-freetext" href="https://llvm.org/docs/ScudoHardenedAllocator.html" id="LPlnk657489" previewremoved="true">
https://llvm.org/docs/ScudoHardenedAllocator.html</a></p>
<p>So perhaps you could build and use it on Linux as shown in <a class="moz-txt-link-freetext" href="https://llvm.org/docs/ScudoHardenedAllocator.html#library" id="LPlnk92418" previewremoved="true">
https://llvm.org/docs/ScudoHardenedAllocator.html#library</a></p>
<p>Besides a potential bug in the allocator, it might be that the S57 driver has a memory allocation pattern that doesn't please Scudo.</p>
<p>Assuming that the problematic memory allocations are done using GDAL's VSIMalloc() (and not C++ new/delete), then have a look at the various #define that you can set at the top of port/cpl_vsisimple.cpp and can be used to trace memory allocations<br>
</p>
<p>// Uncomment to check consistent usage of VSIMalloc(), VSIRealloc(),<br>
// VSICalloc(), VSIFree(), VSIStrdup().<br>
// #define DEBUG_VSIMALLOC<br>
<br>
// Uncomment to compute memory usage statistics.<br>
// DEBUG_VSIMALLOC must also be defined.<br>
// #define DEBUG_VSIMALLOC_STATS<br>
<br>
// Uncomment to print every memory allocation or deallocation.<br>
// DEBUG_VSIMALLOC must also be defined.<br>
// #define DEBUG_VSIMALLOC_VERBOSE<br>
<br>
// Number of bytes of the malloc/calloc/free that triggers a debug trace.<br>
// Can be 0 for all allocs.<br>
#define THRESHOLD_PRINT 10000<br>
<br>
Even<br>
<br>
<br>
</p>
<div class="moz-cite-prefix">Le 28/03/2022 à 14:58, Philippe Lelong a écrit :<br>
</div>
<blockquote type="cite">
<div id="divtagdefaultwrapper" dir="ltr">
<p>Hi,</p>
<p><br>
</p>
<p><span>I am searching for this issue for months now, and cannot find any solution.</span><br>
</p>
<p><br>
To make a long story short, we are using GDAL to decode OGR/S57 charts for years now. We are facing numerous crashes under Android 11 and up if and only if this Android 11 implementation is using SCUDO as a memory allocator (if jemalloc is used no problems).
 We face this problem with an old GDAL2.1.3 version, so we updated to GDAL 3.4.1 but the issue is the same.</p>
<p><br>
</p>
<p>What I can see is that the memory grows exponentially until no more memory is available and crash, even on systems with huge memory available while an Android device without SCUDO and very limited memory (let's say 4Gb) in the same exact conditions, with
 the same apk, runs perfectly. The logcat command show this:</p>
<p> </p>
<div><span>03-28 12:40:34.255  4959  5005 W libc    : malloc(264196) failed: returning null pointer</span><br>
</div>
<div>03-28 12:40:34.255  4959  5005 W libc    : malloc(264196) failed: returning null pointer</div>
<div>03-28 12:40:34.256  4959  5005 W libc    : malloc(264196) failed: returning null pointer</div>
<div>03-28 12:40:34.256  4959  5005 W libc    : malloc(264196) failed: returning null pointer</div>
<div>03-28 12:40:34.612   630   630 D io_stats: !@ Write_top(KB): kworker/u16:1(32583) 8</div>
<div>03-28 12:40:34.820  4959  5041 I scudo   : Scudo ERROR: out of memory trying to allocate 64 bytes</div>
<div>03-28 12:40:34.820  4959  5042 I scudo   : Scudo ERROR: out of memory trying to allocate 64 bytes</div>
<div>03-28 12:40:34.820  4959  5033 I scudo   : Scudo ERROR: out of memory trying to allocate 64 bytes</div>
<div>03-28 12:40:34.820  4959  5031 I scudo   : Scudo ERROR: out of memory trying to allocate 64 bytes</div>
<div>03-28 12:40:34.820  4959  5038 I scudo   : Scudo ERROR: out of memory trying to allocate 64 bytes</div>
<div>03-28 12:40:34.820  4959  5040 I scudo   : Scudo ERROR: out of memory trying to allocate 64 bytes</div>
<div><br>
</div>
<div>and then crash</div>
<div><br>
</div>
<div>Any help on how to debug and eventually fix this would be highly appreciated.</div>
<div><br>
</div>
<div>Best regards,</div>
<div>Philippe from qtVlm development team.</div>
<div><br>
</div>
</div>
<br>
<fieldset class="moz-mime-attachment-header"></fieldset>
<pre class="moz-quote-pre">_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">-- 
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</div>
</div>
</div>
</body>
</html>