1
- /*
1
+ /*
2
2
* Copyright (C) 2015, 2022 Tokyo System House Co.,Ltd.
3
3
* Copyright (C) 2022-2024 Simon Sobisch
4
4
*
@@ -71,13 +71,13 @@ static SQLVARLIST *_sql_var_lists = NULL;
71
71
static SQLVARLIST * _sql_var_lists_last = NULL ;
72
72
static SQLVARLIST * _sql_res_var_lists = NULL ;
73
73
static SQLVARLIST * _sql_res_var_lists_last = NULL ;
74
+ static SQLVARLIST * _pool_sql_var_list = NULL ; // Pool of SQLVARLIST items
74
75
static int _var_lists_length = 0 ;
75
76
static int _res_var_lists_length = 0 ;
76
77
static int _occurs_length = 0 ;
77
78
static int _occurs_iter = 0 ;
78
79
static int _occurs_is_parent = 0 ;
79
80
80
-
81
81
static void sqlca_initialize (struct sqlca_t * );
82
82
83
83
/* sql var list */
@@ -491,7 +491,7 @@ _ocesqlConnectMain(struct sqlca_t *st, char *name, char *user, char *passwd, cha
491
491
int connlen = 0 ;
492
492
493
493
LOG ("dbname = %s\n" ,name );
494
- LOG ("user = %s\n" ,user );
494
+ LOG ("user = %s\n" ,user );
495
495
LOG ("password = %s\n" ,passwd );
496
496
LOG ("connname = %s\n" ,conndbname );
497
497
@@ -2366,9 +2366,17 @@ reset_sql_var_list(void){
2366
2366
* <Outline>
2367
2367
* 埋め込みSQLリスト生成
2368
2368
*/
2369
- static inline SQLVARLIST *
2370
- new_sql_var_list (void ){
2371
- return (SQLVARLIST * )calloc (1 , sizeof (SQLVARLIST ));
2369
+
2370
+ static inline SQLVARLIST * new_sql_var_list (void ) {
2371
+ SQLVARLIST * new_item ;
2372
+ if (_pool_sql_var_list != NULL ) {
2373
+ new_item = _pool_sql_var_list ;
2374
+ _pool_sql_var_list = _pool_sql_var_list -> next ;
2375
+ new_item -> next = NULL ; // Initialize the item
2376
+ } else {
2377
+ new_item = (SQLVARLIST * )calloc (1 , sizeof (SQLVARLIST ));
2378
+ }
2379
+ return new_item ;
2372
2380
}
2373
2381
2374
2382
/*
@@ -3261,7 +3269,7 @@ set_varchar_length(int len, char *dest){
3261
3269
for (i = 0 ; i < OCDB_VARCHAR_HEADER_BYTE ; i ++ ){
3262
3270
c = 0xf & (len >> (i * 4 ));
3263
3271
dest [OCDB_VARCHAR_HEADER_BYTE - i - 1 ] =
3264
- (c > 9 ) ? (c + 'A' - 10 ) : (c + '0' );
3272
+ (c > 9 ) ? (c + 'A' - 10 ) : (c + '0' );
3265
3273
}
3266
3274
}
3267
3275
return ;
@@ -3286,17 +3294,38 @@ static void show_sql_var_list(SQLVARLIST *p){
3286
3294
* <Input>
3287
3295
* @SQLVARLIST *
3288
3296
*/
3289
- static void
3290
- clear_sql_var_list (SQLVARLIST * p ){
3291
- if (p != NULL ){
3292
- clear_sql_var_list (p -> next );
3293
- if (p -> sv .data )
3294
- free (p -> sv .data );
3295
- if (p -> sv .realdata )
3296
- free (p -> sv .realdata );
3297
- free (p );
3297
+ static void clear_sql_var_list (SQLVARLIST * p ) {
3298
+ if (p == NULL )
3299
+ return ; // Nothing to clear
3300
+
3301
+ SQLVARLIST * temp = p ;
3302
+ SQLVARLIST * last_item = NULL ;
3303
+ while (temp != NULL ) {
3304
+ SQLVARLIST * next = temp -> next ;
3305
+ if (temp -> sv .data )
3306
+ free (temp -> sv .data );
3307
+ if (temp -> sv .realdata )
3308
+ free (temp -> sv .realdata );
3309
+ // Initialize the item before returning it to the pool
3310
+ memset (& temp -> sv , 0 , sizeof (SQLVAR ));
3311
+ last_item = temp ;
3312
+ temp = next ;
3313
+ }
3314
+ // Return the entire list to the pool
3315
+ last_item -> next = _pool_sql_var_list ;
3316
+ _pool_sql_var_list = p ;
3317
+ }
3318
+
3319
+ #if 0
3320
+ /* free memory, this shoulkd be called at program exit, currently unused */
3321
+ static void cleanup_sql_var_pool (void ) {
3322
+ while (_pool_sql_var_list != NULL ) {
3323
+ SQLVARLIST * next = _pool_sql_var_list -> next ;
3324
+ free (_pool_sql_var_list );
3325
+ _pool_sql_var_list = next ;
3298
3326
}
3299
3327
}
3328
+ #endif
3300
3329
3301
3330
static void
3302
3331
_ocesqlReleaseConnection (int status , void * arg ){
0 commit comments