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

Reply via email to