Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expanded sql leak #500

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions ext/sqlite3/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ rb_sqlite3_raise(sqlite3 *db, int status)
* accepts a sqlite3 error message as the final argument, which will be `sqlite3_free`d
*/
void
rb_sqlite3_raise_msg(sqlite3 *db, int status, const char* msg)
rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg)
{
VALUE exception;
VALUE exception;

if (status == SQLITE_OK) {
return;
}
if (status == SQLITE_OK) {
return;
}

exception = rb_exc_new2(rb_path2class("SQLite3::Exception"), msg);
sqlite3_free((void*)msg);
rb_iv_set(exception, "@code", INT2FIX(status));
rb_exc_raise(exception);
exception = rb_exc_new2(rb_path2class("SQLite3::Exception"), msg);
sqlite3_free((void *)msg);
rb_iv_set(exception, "@code", INT2FIX(status));
rb_exc_raise(exception);
}
2 changes: 1 addition & 1 deletion ext/sqlite3/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#define CHECK_MSG(_db, _status, _msg) rb_sqlite3_raise_msg(_db, _status, _msg);

void rb_sqlite3_raise(sqlite3 *db, int status);
void rb_sqlite3_raise_msg(sqlite3 *db, int status, const char* msg);
void rb_sqlite3_raise_msg(sqlite3 *db, int status, const char *msg);

#endif
9 changes: 8 additions & 1 deletion ext/sqlite3/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,10 +622,17 @@ static VALUE
get_expanded_sql(VALUE self)
{
sqlite3StmtRubyPtr ctx;
char *expanded_sql;
VALUE rb_expanded_sql;

TypedData_Get_Struct(self, sqlite3StmtRuby, &statement_type, ctx);
REQUIRE_OPEN_STMT(ctx);

return rb_obj_freeze(SQLITE3_UTF8_STR_NEW2(sqlite3_expanded_sql(ctx->st)));
expanded_sql = sqlite3_expanded_sql(ctx->st);
rb_expanded_sql = rb_obj_freeze(SQLITE3_UTF8_STR_NEW2(expanded_sql));
sqlite3_free(expanded_sql);

return rb_expanded_sql;
}

void
Expand Down
Loading