SQLite Forum

memory leaks in sqlite3.c:23545
Login
Building on the discovery in [forumpost/9a0ee040bc](https://sqlite.org/forum/forumpost/9a0ee040bc). Below is the patch @[6a01e4c444b072e3](https://www.sqlite.org/src/info/6a01e4c444b072e3) that seems to clear the leak.

It may be prudent to audit the code for more instances of `goto` jumps ... 


```
Index: src/shell.c.in
==================================================================
--- src/shell.c.in
+++ src/shell.c.in
@@ -8042,10 +8042,11 @@
     }
     sqlite3_free(zSql);
     if( rc ){
       if (pStmt) sqlite3_finalize(pStmt);
       utf8_printf(stderr,"Error: %s\n", sqlite3_errmsg(p->db));
+      sqlite3_free(sCtx.z);
       xCloser(sCtx.in);
       rc = 1;
       goto meta_command_exit;
     }
     nCol = sqlite3_column_count(pStmt);
@@ -8071,10 +8072,11 @@
     rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
     sqlite3_free(zSql);
     if( rc ){
       utf8_printf(stderr, "Error: %s\n", sqlite3_errmsg(p->db));
       if (pStmt) sqlite3_finalize(pStmt);
+      sqlite3_free(sCtx.z);
       xCloser(sCtx.in);
       rc = 1;
       goto meta_command_exit;
     }
     needCommit = sqlite3_get_autocommit(p->db);

```