Skip to content

Conversation

@alisdair
Copy link
Contributor

@alisdair alisdair commented Nov 2, 2025

Updates tailscale/corp#34015

@alisdair alisdair requested review from bradfitz and raggi November 2, 2025 16:21
@fserb
Copy link

fserb commented Nov 2, 2025

Randomly jumping in on this. Isn't this true for all strings SQLite returns? Should we fix SQL() above and the other cases in cgosqlite? Like column names and errors?

@alisdair
Copy link
Contributor Author

alisdair commented Nov 2, 2025

No, this is a special case:

sqlite/cgosqlite/sqlite3.h

Lines 4565 to 4570 in 77567f4

** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P)
** are managed by SQLite and are automatically freed when the prepared
** statement is finalized.
** ^The string returned by sqlite3_expanded_sql(P), on the other hand,
** is obtained from [sqlite3_malloc()] and must be freed by the application
** by passing it to [sqlite3_free()].

}
}

func TestExpandedSQL(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's too tedious to make this look for leaks, eh?

(probably not visible to https://pkg.go.dev/runtime#ReadMemStats ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just too fiddly for me on a Sunday morning. I would like to try it tomorrow though.

@alisdair alisdair force-pushed the alisdair/expandedsql-free branch from 4cc49d5 to 80904c6 Compare November 2, 2025 16:41
@alisdair alisdair force-pushed the alisdair/expandedsql-free branch from 80904c6 to 1352947 Compare November 2, 2025 16:42
@alisdair alisdair merged commit 6cfe794 into main Nov 2, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants