Skip to content

Commit 1cdaa42

Browse files
authored
Merge pull request #500 from sparklemotion/flavorjones-fix-expanded-sql-leak
fix: expanded sql leak
2 parents a313b9a + 979e8b2 commit 1cdaa42

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

ext/sqlite3/exception.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ rb_sqlite3_raise(sqlite3 *db, int status)
102102
* accepts a sqlite3 error message as the final argument, which will be `sqlite3_free`d
103103
*/
104104
void
105-
rb_sqlite3_raise_msg(sqlite3 *db, int status, const char* msg)
105+
rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg)
106106
{
107-
VALUE exception;
107+
VALUE exception;
108108

109-
if (status == SQLITE_OK) {
110-
return;
111-
}
109+
if (status == SQLITE_OK) {
110+
return;
111+
}
112112

113-
exception = rb_exc_new2(rb_path2class("SQLite3::Exception"), msg);
114-
sqlite3_free((void*)msg);
115-
rb_iv_set(exception, "@code", INT2FIX(status));
116-
rb_exc_raise(exception);
113+
exception = rb_exc_new2(rb_path2class("SQLite3::Exception"), msg);
114+
sqlite3_free((void *)msg);
115+
rb_iv_set(exception, "@code", INT2FIX(status));
116+
rb_exc_raise(exception);
117117
}

ext/sqlite3/exception.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
#define CHECK_MSG(_db, _status, _msg) rb_sqlite3_raise_msg(_db, _status, _msg);
66

77
void rb_sqlite3_raise(sqlite3 *db, int status);
8-
void rb_sqlite3_raise_msg(sqlite3 *db, int status, const char* msg);
8+
void rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg);
99

1010
#endif

ext/sqlite3/statement.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,17 @@ static VALUE
622622
get_expanded_sql(VALUE self)
623623
{
624624
sqlite3StmtRubyPtr ctx;
625+
char *expanded_sql;
626+
VALUE rb_expanded_sql;
627+
625628
TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
626629
REQUIRE_OPEN_STMT(ctx);
627630

628-
return rb_obj_freeze(SQLITE3_UTF8_STR_NEW2(sqlite3_expanded_sql(ctx->st)));
631+
expanded_sql = sqlite3_expanded_sql(ctx->st);
632+
rb_expanded_sql = rb_obj_freeze(SQLITE3_UTF8_STR_NEW2(expanded_sql));
633+
sqlite3_free(expanded_sql);
634+
635+
return rb_expanded_sql;
629636
}
630637

631638
void

0 commit comments

Comments
 (0)