[Home]

Summary:ASTERISK-12410: [patch] correct the use of errormsg according to the API and implementation of SQLite.
Reporter:Guillaume Knispel (gknispel_proformatique)Labels:
Date Opened:2008-07-18 12:25:56Date Closed:2008-07-31 14:34:56
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Resources/res_config_sqlite
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) res_config_sqlite_errormsg.patch
Description:The attached patch corrects the use of errormsg according to the SQLite API and implementation. It also removes the loop on SQLITE_LOCKED conditions (looping on SQLITE_BUSY condition is OK).

errormsg is dynamically allocated both in some internal layers of the SQLite library and reallocated just before the SQLite function exits. SQLite can't give us any hard warranty that the allocation (first or subsequent) of the errormsg will succeed, and if it fails errormsg will remain NULL despite error being set.

Also, I'm not sure that errormsg will always remain NULL on success, so I added / moved some sqlite_freemem() so that it is always called. sqlite_freemem() is just a wrapper around free(), so sqlite_freemem(NULL) is a noop, so this is always safe.

An other thing is that in RES_CONFIG_SQLITE_BEGIN / RES_CONFIG_SQLITE_END loops, errormsg can be allocated on busy condition but it was never freed in the loop.

Finally, there should be no retry after an SQLITE_LOCKED error as http://www.sqlite.org/c_interface.html says that SQLITE_LOCKED is a busy conditions caused by recursion of sqlite_exec calls in a callback of a previous one, and this is only allowed for read only access - when one tries to do that in a RW way he gets a SQLITE_LOCKED. So retrying the query will just yield to the same result in that case.
Comments:By: Digium Subversion (svnbot) 2008-07-31 14:34:54

Repository: asterisk
Revision: 134919

U   trunk/res/res_config_sqlite.c

------------------------------------------------------------------------
r134919 | tilghman | 2008-07-31 14:34:53 -0500 (Thu, 31 Jul 2008) | 6 lines

Two errors:
1) If a function returns SQLITE_LOCKED, no recovery is possible.
2) An error message can be allocated, even when no error is signalled.
(closes issue ASTERISK-12410)
Reported by: gknispel_proformatique

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=134919