@@ -42,6 +42,9 @@ _sqlite3_user_delete(sqlite3* db, const char* zUsername)
42
42
}
43
43
*/
44
44
import "C"
45
+ import (
46
+ "unsafe"
47
+ )
45
48
46
49
const (
47
50
SQLITE_AUTH = C .SQLITE_AUTH
@@ -61,7 +64,17 @@ const (
61
64
// If the SQLITE_USER table is not present in the database file, then
62
65
// this interface is a harmless no-op returnning SQLITE_OK.
63
66
func (c * SQLiteConn ) Authenticate (username , password string ) error {
64
- rv := C ._sqlite3_user_authenticate (c .db , C .CString (username ), C .CString (password ), C .int (len (password )))
67
+ // Allocate C Variables
68
+ cuser := C .CString (username )
69
+ cpass := C .CString (password )
70
+
71
+ // Free C Variables
72
+ defer func () {
73
+ C .free (unsafe .Pointer (cuser ))
74
+ C .free (unsafe .Pointer (cpass ))
75
+ }()
76
+
77
+ rv := C ._sqlite3_user_authenticate (c .db , cuser , cpass , C .int (len (password )))
65
78
if rv != C .SQLITE_OK {
66
79
return c .lastError ()
67
80
}
@@ -83,7 +96,17 @@ func (c *SQLiteConn) AuthUserAdd(username, password string, admin bool) error {
83
96
isAdmin = 1
84
97
}
85
98
86
- rv := C ._sqlite3_user_add (c .db , C .CString (username ), C .CString (password ), C .int (len (password )), C .int (isAdmin ))
99
+ // Allocate C Variables
100
+ cuser := C .CString (username )
101
+ cpass := C .CString (password )
102
+
103
+ // Free C Variables
104
+ defer func () {
105
+ C .free (unsafe .Pointer (cuser ))
106
+ C .free (unsafe .Pointer (cpass ))
107
+ }()
108
+
109
+ rv := C ._sqlite3_user_add (c .db , cuser , cpass , C .int (len (password )), C .int (isAdmin ))
87
110
if rv != C .SQLITE_OK {
88
111
return c .lastError ()
89
112
}
@@ -102,7 +125,17 @@ func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error
102
125
isAdmin = 1
103
126
}
104
127
105
- rv := C ._sqlite3_user_change (c .db , C .CString (username ), C .CString (password ), C .int (len (password )), C .int (isAdmin ))
128
+ // Allocate C Variables
129
+ cuser := C .CString (username )
130
+ cpass := C .CString (password )
131
+
132
+ // Free C Variables
133
+ defer func () {
134
+ C .free (unsafe .Pointer (cuser ))
135
+ C .free (unsafe .Pointer (cpass ))
136
+ }()
137
+
138
+ rv := C ._sqlite3_user_change (c .db , cuser , cpass , C .int (len (password )), C .int (isAdmin ))
106
139
if rv != C .SQLITE_OK {
107
140
return c .lastError ()
108
141
}
@@ -116,7 +149,15 @@ func (c *SQLiteConn) AuthUserChange(username, password string, admin bool) error
116
149
// the database cannot be converted into a no-authentication-required
117
150
// database.
118
151
func (c * SQLiteConn ) AuthUserDelete (username string ) error {
119
- rv := C ._sqlite3_user_delete (c .db , C .CString (username ))
152
+ // Allocate C Variables
153
+ cuser := C .CString (username )
154
+
155
+ // Free C Variables
156
+ defer func () {
157
+ C .free (unsafe .Pointer (cuser ))
158
+ }()
159
+
160
+ rv := C ._sqlite3_user_delete (c .db , cuser )
120
161
if rv != C .SQLITE_OK {
121
162
return c .lastError ()
122
163
}
0 commit comments