Permalink
Browse files

Sqlite 325 (#1268)

* Update Sqlite to 3.25.3

* Fix a memory leak when opening a sqlite database fails.

* More sqlite leak fixes, and better error messages.
  • Loading branch information...
shawnw committed Nov 22, 2018
1 parent cba557f commit 3f6603686d872781a6e5446d72d32ba65eb7360a
Showing with 211 additions and 137 deletions.
  1. +1 −1 CHANGES.188.md
  2. +3 −3 hdrs/sqlite3.h
  3. +8 −7 src/connlog.c
  4. +34 −25 src/db.c
  5. +1 −1 src/destroy.c
  6. +2 −2 src/funtime.c
  7. +5 −5 src/help.c
  8. +1 −1 src/markup.c
  9. +2 −2 src/plyrlist.c
  10. +14 −7 src/sql.c
  11. +139 −82 src/sqlite3.c
  12. +1 −1 src/wiz.c
@@ -47,7 +47,7 @@ Minor Changes
* Wildcard patterns are sometimes converted to regular expressions when matched against many strings. [SW]
* Add '--disable-socket-quota' option for our test suite. [GM]
* The list of color definitions used with `ansi()`, `colors()`, etc. is now kept in game/txt/colors.json. [SW]
* Sqlite3 updated to 3.25.1. Biggest user-visible change is support for window functions. [SW]
* Sqlite3 updated to 3.25.3. Biggest user-visible change is support for window functions. [SW]
Softcode
--------
@@ -123,9 +123,9 @@ extern "C" {
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
** [sqlite_version()] and [sqlite_source_id()].
*/
#define SQLITE_VERSION "3.25.1"
#define SQLITE_VERSION_NUMBER 3025001
#define SQLITE_SOURCE_ID "2018-09-18 20:20:44 2ac9003de44da7dafa3fbb1915ac5725a9275c86bf2f3b7aa19321bf1460b386"
#define SQLITE_VERSION "3.25.3"
#define SQLITE_VERSION_NUMBER 3025003
#define SQLITE_SOURCE_ID "2018-11-05 20:37:38 89e099fbe5e13c33e683bef07361231ca525b88f7907be7092058007b75036f2"
/*
** CAPI3REF: Run-Time Library Version Numbers
@@ -364,7 +364,7 @@ connlog_connection(const char *ip, const char *host, bool ssl)
id = sqlite3_last_insert_rowid(connlog_db);
} else {
do_rawlog(LT_ERR, "Failed to record connection timestamp from %s: %s", ip,
sqlite3_errstr(status));
sqlite3_errmsg(connlog_db));
sqlite3_exec(connlog_db, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return -1;
}
@@ -396,7 +396,7 @@ connlog_connection(const char *ip, const char *host, bool ssl)
sqlite3_reset(adder);
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Failed to record connection from %s: %s", ip,
sqlite3_errstr(status));
sqlite3_errmsg(connlog_db));
sqlite3_exec(connlog_db, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return -1;
}
@@ -432,7 +432,7 @@ connlog_login(int64_t id, dbref player)
sqlite3_reset(login);
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Failed to record login to #%d: %s", player,
sqlite3_errstr(status));
sqlite3_errmsg(connlog_db));
}
}
@@ -457,7 +457,7 @@ connlog_set_websocket(int64_t id)
sqlite3_reset(ws);
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Failed to record websocket for connlog id %lld: %s",
(long long) id, sqlite3_errstr(status));
(long long) id, sqlite3_errmsg(connlog_db));
}
}
@@ -767,7 +767,7 @@ FUNCTION(fun_connlog)
if (status != SQLITE_DONE) {
*bp = sbp;
safe_format(buff, bp, "#-1 SQLITE ERROR %s", sqlite3_errstr(status));
safe_format(buff, bp, "#-1 SQLITE ERROR %s", sqlite3_errmsg(connlog_db));
}
sqlite3_finalize(search);
return;
@@ -848,7 +848,7 @@ FUNCTION(fun_connrecord)
safe_str(sep, buff, bp);
safe_integer(sqlite3_column_int(rec, 8), buff, bp);
} else if (status != SQLITE_DONE) {
safe_format(buff, bp, "#-1 SQLITE ERROR %s", sqlite3_errstr(status));
safe_format(buff, bp, "#-1 SQLITE ERROR %s", sqlite3_errmsg(connlog_db));
} else {
safe_str("#-1 NO SUCH RECORD", buff, bp);
}
@@ -955,7 +955,8 @@ FUNCTION(fun_addrlog)
if (rc != SQLITE_DONE) {
*bp = sbp;
safe_format(buff, bp, T("#-1 SQLITE ERROR: %s"), sqlite3_errstr(rc));
safe_format(buff, bp, T("#-1 SQLITE ERROR: %s"),
sqlite3_errmsg(connlog_db));
}
sqlite3_finalize(stmt);
@@ -1374,8 +1374,9 @@ db_read_attrs(PENNFILE *f, dbref i, int count)
}
if (found != count)
do_rawlog(LT_ERR, "WARNING: Actual attribute count (%d) different than "
"expected count (%d).",
do_rawlog(LT_ERR,
"WARNING: Actual attribute count (%d) different than "
"expected count (%d).",
found, count);
}
@@ -2158,7 +2159,7 @@ sql_from_hexstr_fun(sqlite3_context *ctx, int nargs __attribute__((unused)),
sqlite3 *
open_sql_db(const char *name, bool nocreate)
{
sqlite3 *db;
sqlite3 *db = NULL;
int status;
int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_URI | SQLITE_OPEN_NOMUTEX;
@@ -2172,14 +2173,18 @@ open_sql_db(const char *name, bool nocreate)
if ((status = sqlite3_open_v2(name, &db, flags, NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR, "Unable to open sqlite3 database %s: %s",
*name ? name : ":unnamed:", sqlite3_errstr(status));
*name ? name : ":unnamed:",
db ? sqlite3_errmsg(db) : sqlite3_errstr(status));
if (db) {
sqlite3_close(db);
}
return NULL;
}
if ((status = sqlite3_create_collation(db, "TRAILNUMBERS", SQLITE_UTF8, NULL,
comp_trailing_numbers)) != SQLITE_OK) {
do_rawlog(LT_ERR,
"Unable to attach TRAILNUMBERS collator to database %s: %s",
*name ? name : ":unnamed:", sqlite3_errstr(status));
*name ? name : ":unnamed:", sqlite3_errmsg(db));
}
#ifdef HAVE_ICU
@@ -2191,13 +2196,13 @@ open_sql_db(const char *name, bool nocreate)
db, "regexp", 2, SQLITE_UTF8 | SQLITE_DETERMINISTIC, NULL,
sql_regexp_fun, NULL, NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR, "Unable to register sqlite3 regexp() function: %s",
sqlite3_errstr(status));
sqlite3_errmsg(db));
}
if ((status = sqlite3_create_function(
db, "from_hexstr", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC, NULL,
sql_from_hexstr_fun, NULL, NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR, "Unable to register sqlite3 from_hexstr() function: %s",
sqlite3_errstr(status));
sqlite3_errmsg(db));
}
sqlite3_spellfix_init(db, NULL, NULL);
sqlite3_remember_init(db, NULL, NULL);
@@ -2292,7 +2297,7 @@ close_sql_db(sqlite3 *db)
&delete_all_stmts, NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR,
"Unable to prepare query statement_cache.delete_all: %s",
sqlite3_errstr(status));
sqlite3_errmsg(db));
delete_all_stmts = NULL;
}
}
@@ -2304,7 +2309,7 @@ close_sql_db(sqlite3 *db)
&find_all_stmts, NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR,
"Unable to prepare query statement_cache.find_all: %s",
sqlite3_errstr(status));
sqlite3_errmsg(db));
find_all_stmts = NULL;
}
}
@@ -2349,7 +2354,7 @@ sqlite3_stmt *
prepare_statement_cache(sqlite3 *db, const char *query, const char *name,
bool cache)
{
sqlite3_stmt *stmt;
sqlite3_stmt *stmt = NULL;
int status;
int flags = cache ? SQLITE_PREPARE_PERSISTENT : 0;
@@ -2365,8 +2370,11 @@ prepare_statement_cache(sqlite3 *db, const char *query, const char *name,
SQLITE_OPEN_FULLMUTEX,
NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR, "Unable to create prepared statement cache: %s",
sqlite3_errstr(status));
statement_cache = NULL;
db ? sqlite3_errmsg(statement_cache) : sqlite3_errstr(status));
if (statement_cache) {
sqlite3_close(statement_cache);
statement_cache = NULL;
}
return NULL;
}
@@ -2379,7 +2387,7 @@ prepare_statement_cache(sqlite3 *db, const char *query, const char *name,
do_rawlog(LT_ERR, "Unable to build prepared statement cache table: %s",
errmsg);
sqlite3_free(errmsg);
sqlite3_close_v2(statement_cache);
sqlite3_close(statement_cache);
statement_cache = NULL;
return NULL;
}
@@ -2392,7 +2400,7 @@ prepare_statement_cache(sqlite3 *db, const char *query, const char *name,
SQLITE_PREPARE_PERSISTENT, &find_stmt,
NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR, "Unable to prepare query statement_cache.find: %s",
sqlite3_errstr(status));
sqlite3_errmsg(statement_cache));
find_stmt = NULL;
return NULL;
}
@@ -2405,7 +2413,7 @@ prepare_statement_cache(sqlite3 *db, const char *query, const char *name,
SQLITE_PREPARE_PERSISTENT, &insert_stmt,
NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR, "Unable to prepare query statement_cache.insert: %s",
sqlite3_errstr(status));
sqlite3_errmsg(statement_cache));
insert_stmt = NULL;
return NULL;
}
@@ -2430,7 +2438,7 @@ prepare_statement_cache(sqlite3 *db, const char *query, const char *name,
if ((status = sqlite3_prepare_v3(db, query, -1, flags, &stmt, NULL)) !=
SQLITE_OK) {
do_rawlog(LT_ERR, "Unable to prepare query %s: %s", name,
sqlite3_errstr(status));
sqlite3_errmsg(db));
return NULL;
}
@@ -2467,7 +2475,7 @@ close_statement(sqlite3_stmt *stmt)
NULL)) != SQLITE_OK) {
do_rawlog(LT_ERR,
"Unable to prepare query statement_cache.delete_one: %s",
sqlite3_errstr(status));
sqlite3_errmsg(statement_cache));
delete_stmt = NULL;
return;
}
@@ -2528,10 +2536,11 @@ set_objdata(dbref thing, const char *keybase, void *data)
}
sqldb = get_shared_db();
setter = prepare_statement(
sqldb, "INSERT INTO objdata(dbref, key, ptr) VALUES(?, ?, ?) ON "
"CONFLICT (dbref, key) DO UPDATE SET ptr=excluded.ptr",
"objdata.set");
setter =
prepare_statement(sqldb,
"INSERT INTO objdata(dbref, key, ptr) VALUES(?, ?, ?) ON "
"CONFLICT (dbref, key) DO UPDATE SET ptr=excluded.ptr",
"objdata.set");
if (!setter) {
return NULL;
}
@@ -2546,7 +2555,7 @@ set_objdata(dbref thing, const char *keybase, void *data)
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to execute objdata set query for #%d/%s: %s",
thing, keybase, sqlite3_errstr(status));
thing, keybase, sqlite3_errmsg(sqldb));
}
sqlite3_reset(setter);
@@ -2582,7 +2591,7 @@ get_objdata(dbref thing, const char *keybase)
data = (void *) ((intptr_t) sqlite3_column_int64(getter, 0));
} else if (status != SQLITE_DONE) {
do_rawlog(LT_TRACE, "Unable to execute objdata get query for #%d/%s: %s",
thing, keybase, sqlite3_errstr(status));
thing, keybase, sqlite3_errmsg(sqldb));
}
sqlite3_reset(getter);
return data;
@@ -2613,7 +2622,7 @@ delete_objdata(dbref thing, const char *keybase)
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to execute objdata delete query for #%d: %s",
thing, sqlite3_errstr(status));
thing, sqlite3_errmsg(sqldb));
}
sqlite3_reset(deleter);
}
@@ -2634,7 +2643,7 @@ add_object_table(dbref obj)
} while (is_busy_status(status));
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to add #%d to objects table: %s", obj,
sqlite3_errstr(status));
sqlite3_errmsg(sqldb));
}
sqlite3_reset(adder);
}
@@ -771,7 +771,7 @@ free_object(dbref thing)
} while (is_busy_status(status));
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to delete #%d from objects table: %s", thing,
sqlite3_errstr(status));
sqlite3_errmsg(sqldb));
}
sqlite3_reset(deleter);
}
@@ -1127,7 +1127,7 @@ FUNCTION(fun_timecalc)
safe_str("#-1 DATE ERROR", buff, bp);
}
} else {
safe_format(buff, bp, "#-1 %s", sqlite3_errstr(status));
safe_format(buff, bp, "#-1 %s", sqlite3_errmsg(db));
}
sqlite3_finalize(timer);
}
@@ -1171,7 +1171,7 @@ FUNCTION(fun_secscalc)
safe_str("#-1 DATE ERROR", buff, bp);
}
} else {
safe_format(buff, bp, "#-1 %s", sqlite3_errstr(status));
safe_format(buff, bp, "#-1 %s", sqlite3_errmsg(db));
}
sqlite3_finalize(timer);
}
@@ -540,7 +540,7 @@ build_help_file(help_file *h)
status = sqlite3_step(add_cat);
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to add %s to suggestions: %s", h->command,
sqlite3_errstr(status));
sqlite3_errmsg(sqldb));
sqlite3_exec(help_db, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
sqlite3_exec(sqldb, "ROLLBACK TRANSACTION", NULL, NULL, NULL);
return 0;
@@ -945,7 +945,7 @@ write_topic(help_file *h, const char *body)
} while (is_busy_status(status));
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to insert help entry body: %s\n",
sqlite3_errstr(status));
sqlite3_errmsg(help_db));
sqlite3_reset(query);
return;
}
@@ -979,7 +979,7 @@ write_topic(help_file *h, const char *body)
do_rawlog(
LT_ERR,
"Unable to insert help topic %s: %s (Possible duplicate entry?)",
cur->topic, sqlite3_errstr(status));
cur->topic, sqlite3_errmsg(help_db));
} else {
sqlite3_bind_text(add_suggest, 1, cur->topic, -1, SQLITE_STATIC);
sqlite3_step(add_suggest);
@@ -1401,12 +1401,12 @@ help_build_index(help_file *h)
sqlite3_bind_int(adder, 2, page);
sqlite3_bind_text(adder, 3, t, -1, SQLITE_TRANSIENT);
status = sqlite3_step(adder);
sqlite3_reset(adder);
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "While building entries database for %s: %s",
h->command, sqlite3_errstr(status));
h->command, sqlite3_errmsg(help_db));
break;
}
sqlite3_reset(adder);
page += 1;
count = 0;
}
@@ -159,7 +159,7 @@ build_rgb_map(void)
} while (is_busy_status(status));
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to populate colors table: %s",
sqlite3_errstr(status));
sqlite3_errmsg(sqldb));
}
sqlite3_finalize(creator);
unmap_file(mf);
@@ -214,7 +214,7 @@ lookup_player_name(const char *name)
d = sqlite3_column_int(looker, 0);
} else if (status != SQLITE_DONE) {
do_rawlog(LT_ERR, "Unable to run players lookup query for %s: %s", name,
sqlite3_errstr(status));
sqlite3_errmsg(sqldb));
}
sqlite3_reset(looker);
return d;
@@ -244,7 +244,7 @@ delete_player(dbref player)
if (status != SQLITE_DONE) {
do_rawlog(LT_ERR,
"Unable to execute query to delete players names for #%d: %s",
player, sqlite3_errstr(status));
player, sqlite3_errmsg(sqldb));
}
sqlite3_reset(deleter);
}
Oops, something went wrong.

0 comments on commit 3f66036

Please sign in to comment.