If I Interpret your text correctly, you are claiming that your 
mpxMalloc/mpxRealloc is issuing the same address twice, without mpxFree being 
called in between?

Are you tracking mpxRealloc calls correctly? If the area pointed to is not 
large enough, a new area will be allocated, the data copied and the old area 
freed.

Otherwise, it would imply that your memory allocation is faulty because it is 
allocating the same memory twice without an intervening free.


-----Ursprüngliche Nachricht-----
Von: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] Im 
Auftrag von Anthrathodiyil, Sabeel (S.)
Gesendet: Freitag, 24. März 2017 12:19
An: SQLite mailing list <sqlite-users@mailinglists.sqlite.org>
Cc: Subramaniyan, Ganesan (G.) <ganesan.subramani...@visteon.com>; Natanam, 
Karthigeyan (K.) <karthigeyan.nata...@visteon.com>
Betreff: Re: [sqlite] QUERY: Usage of malloc and free in SQLite

Hi Dan,
Custom memory management APIs registered are being used by SQLite. We suspect 
SQLite, in certain cases is freeing allocated memory, not using the registered 
API to free.

As part of our investigation, we are maintaining the starting address of the 
memory allocated and size allocated, and removed from list once it is freed via 
registered memory management API mqxFree. But we find the same address being 
allocated again for a subsequent memory allocation/reallocation request which 
was not freed using mqxFree. This leads us to suspect allocated memory is being 
freed(not through the registered API) and same address is being made available 
for next allocation.

Thanks,
Sabeel

-----Original Message-----
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of Dan Kennedy
Sent: Thursday, March 23, 2017 9:32 PM
To: sqlite-users@mailinglists.sqlite.org
Subject: Re: [sqlite] QUERY: Usage of malloc and free in SQLite

On 03/23/2017 10:00 PM, Subramaniyan, Ganesan (G.) wrote:
> Hi,
> We are facing dynamic memory pool corruption issue while using SQLite. Based 
> on our investigation we suspect SQLite freeing memory bypassing the memory 
> management API'S registered as below.
>
> We have registered the memory allocation routines as below.
> static const sqlite3_mem_methods mqxmem = {
>          mqxMalloc,
>          mqxFree,
>          mqxRealloc,
>          mqxSize,
>          mqxRoundup,
>          mqxInit,
>          mqxShutdown,
>          NULL
>      };
> sqlite3_config(SQLITE_CONFIG_MALLOC, &mqxmem);
>
> Despite this, is there any sort of configurations by which SQLite might still 
> use its own or standard library APIs to allocate/reallocate or free the 
> memory, bypassing the memory management APIs registered above?


No. Following a successful call to sqlite3_config() SQLite allocates and frees 
memory using the configured routines exclusively[1]. There are no direct calls 
to malloc()/free() or similar in the library.

Are you checking the return value of sqlite3_config()? If
sqlite3_initialize() or any other sqlite3_*() function has already been called 
when sqlite3_config() is invoked it will fail and the memory allocation 
routines will not be configured.

   https://sqlite.org/c3ref/config.html

What symptoms are you seeing that suggest SQLite is bypassing your memory 
allocation functions?

Dan.

[1] It may also make use of static buffers supplied by calls to 
sqlite3_config(SQLITE_CONFIG_HEAP), CONFIG_PAGECACHE or CONFIG_SCRATCH, but I'm 
guessing you have made no such calls. Most apps do not.




> We are using SQLite version 3.7.10 running on Freescale MQX hosted on ARM A5 
> Cortex processor.
> We have enabled SQLITE_ENABLE_MEMORY_MANAGEMENT configuration and using 
> sqlite3_release_memory()<https://www.sqlite.org/c3ref/release_memory.html> 
> very often, after every fetch/write operations.
>
> Thanks & Regards,
> Ganesan.S
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


___________________________________________
 Gunter Hick
Software Engineer
Scientific Games International GmbH
FN 157284 a, HG Wien
Klitschgasse 2-4, A-1130 Vienna, Austria
Tel: +43 1 80100 0
E-Mail: h...@scigames.at

This communication (including any attachments) is intended for the use of the 
intended recipient(s) only and may contain information that is confidential, 
privileged or legally protected. Any unauthorized use or dissemination of this 
communication is strictly prohibited. If you have received this communication 
in error, please immediately notify the sender by return e-mail message and 
delete all copies of the original communication. Thank you for your cooperation.


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to