@@ -20,7 +20,7 @@ struct executeBaton {
2020
2121 Connection *obj;
2222 a_sqlany_stmt *sqlany_stmt;
23- bool prepared_stmt ;
23+ bool free_stmt ;
2424 std::string stmt;
2525 std::vector<char *> string_vals;
2626 std::vector<double *> num_vals;
@@ -38,12 +38,14 @@ struct executeBaton {
3838 obj = NULL ;
3939 sqlany_stmt = NULL ;
4040 rows_affected = -1 ;
41- prepared_stmt = false ;
41+ free_stmt = false ;
4242 }
4343
4444 ~executeBaton () {
4545 obj = NULL ;
46- // the StmtObject will free sqlany_stmt
46+ if ( sqlany_stmt != NULL && free_stmt ) {
47+ api.sqlany_free_stmt ( sqlany_stmt );
48+ }
4749 sqlany_stmt = NULL ;
4850 CLEAN_STRINGS ( string_vals );
4951 CLEAN_STRINGS ( colNames );
@@ -110,7 +112,6 @@ void executeWork( uv_work_t *req )
110112 getErrorMsg ( baton->obj ->conn , baton->error_msg );
111113 return ;
112114 }
113- baton->prepared_stmt = true ;
114115
115116 } else if ( baton->sqlany_stmt == NULL ) {
116117 baton->err = true ;
@@ -185,8 +186,8 @@ void executeAfter( uv_work_t *req )
185186
186187 scoped_lock lock ( baton->obj ->conn_mutex );
187188
188- if ( baton->sqlany_stmt != NULL && baton->prepared_stmt ) {
189- // the StmtObject will free sqlany_stmt
189+ if ( baton->sqlany_stmt != NULL && baton->free_stmt ) {
190+ api. sqlany_free_stmt ( baton-> sqlany_stmt );
190191 baton->sqlany_stmt = NULL ;
191192 }
192193
@@ -237,6 +238,7 @@ NODE_API_FUNC( StmtObject::exec )
237238 executeBaton *baton = new executeBaton ();
238239 baton->obj = obj->connection ;
239240 baton->sqlany_stmt = obj->sqlany_stmt ;
241+ baton->free_stmt = false ;
240242 baton->callback_required = callback_required;
241243
242244 if ( bind_required ) {
@@ -335,6 +337,7 @@ NODE_API_FUNC( Connection::exec )
335337 baton->sqlany_stmt = NULL ;
336338 baton->obj = obj;
337339 baton->callback_required = callback_required;
340+ baton->free_stmt = true ;
338341 baton->stmt = std::string (*param0);
339342
340343 if ( bind_required ) {
0 commit comments