Skip to content

Commit 574ba64

Browse files
committed
Fix memory allocation with Oracle 11g client when querying CLOBs using fetchAsString
1 parent 675e5aa commit 574ba64

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,6 +3324,17 @@ void Connection::DoDefines ( eBaton* executeBaton )
33243324
executeBaton->extDefines[col] = new ExtDefine (
33253325
NJS_EXTDEFINE_CLOBASSTR ) ;
33263326
executeBaton->extDefines[col]->fields.extClobAsStr.ctx = (void *) ctx;
3327+
3328+
executeBaton->extDefines[col]->fields.extClobAsStr.len2 =
3329+
( unsigned int * ) malloc ( sizeof ( unsigned int ) *
3330+
executeBaton->maxRows );
3331+
if( !executeBaton->extDefines[col]->fields.extClobAsStr.len2 )
3332+
{
3333+
executeBaton->error = NJSMessages::getErrorMsg (
3334+
errInsufficientMemory );
3335+
error = true;
3336+
}
3337+
33273338
}
33283339
else
33293340
{
@@ -3369,6 +3380,8 @@ void Connection::DoFetch (eBaton* executeBaton)
33693380
*/
33703381
for ( unsigned int row = 0; row < executeBaton->rowsFetched ; row ++ )
33713382
{
3383+
define->len[row] = ( DPI_BUFLEN_TYPE )
3384+
extDefine->fields.extClobAsStr.len2[row];
33723385
define->len[row] += extDefine->fields.extClobAsStr.cLen ;
33733386
}
33743387
}
@@ -5579,8 +5592,8 @@ int Connection::cbDynBufferGet ( void *ctx, DPI_SZ_TYPE nRows,
55795592
initialized.
55805593
*/
55815594
int Connection::cbDynDefine ( void *octxp, unsigned long definePos,
5582-
unsigned long iter, unsigned long *prevIter,
5583-
void **bufpp, unsigned long **alenpp,
5595+
unsigned int iter, unsigned long *prevIter,
5596+
void **bufpp, unsigned int **alenpp,
55845597
void **indpp, unsigned short **rcodepp )
55855598
{
55865599
eBaton *executeBaton = (eBaton *) octxp ;
@@ -5618,11 +5631,14 @@ int Connection::cbDynDefine ( void *octxp, unsigned long definePos,
56185631
}
56195632
else
56205633
{
5621-
define->len[iter] = maxLen;
5634+
extDefine->fields.extClobAsStr.len2[iter] = maxLen;
56225635
define->ind[iter] = 0; // default value for indicator
56235636

56245637
*bufpp = (void *) (&buf[iter][extDefine->fields.extClobAsStr.cLen]);
5625-
*alenpp = (unsigned long *) &(define->len[iter]) ; // size for this iter
5638+
5639+
// size for this iter
5640+
*alenpp = (unsigned int *) &(extDefine->fields.extClobAsStr.len2[iter]) ;
5641+
56265642
*indpp = (void *) &(define->ind[iter]); // indicator
56275643
}
56285644
return ret ;

src/njs/src/njsConnection.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ typedef struct ExtDefine
240240
{
241241
void *ctx; /* Context pointer used by the call back */
242242
DPI_BUFLEN_TYPE cLen;
243+
unsigned int *len2; /* Length of the buffer */
243244
} extClobAsStr ;
244245
} fields;
245246

@@ -250,6 +251,7 @@ typedef struct ExtDefine
250251
{
251252
fields.extClobAsStr.ctx = NULL ;
252253
fields.extClobAsStr.cLen = 0;
254+
fields.extClobAsStr.len2 = NULL;
253255
}
254256
}
255257
} ExtDefine;
@@ -488,6 +490,8 @@ typedef struct eBaton
488490
{
489491
free ( extDefines[i]->fields.extClobAsStr.ctx );
490492
extDefines[i]->fields.extClobAsStr.ctx = NULL ;
493+
free ( extDefines[i]->fields.extClobAsStr.len2 );
494+
extDefines[i]->fields.extClobAsStr.len2 = NULL ;
491495
delete extDefines[i];
492496
}
493497
}
@@ -682,8 +686,8 @@ class Connection: public Nan::ObjectWrap
682686
unsigned short **rcode, unsigned char *piecep );
683687

684688
static int cbDynDefine ( void *octxp, unsigned long definePos,
685-
unsigned long iter, unsigned long *prevIter,
686-
void **bufpp, unsigned long **alenpp,
689+
unsigned int iter, unsigned long *prevIter,
690+
void **bufpp, unsigned int **alenpp,
687691
void **indpp, unsigned short **rcodepp );
688692

689693
// Callback used in DML-Return SQL statements to

src/njs/src/njsResultSet.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,11 @@ void ResultSet::clearFetchBuffer( unsigned int numRows )
733733
free(defineBuffers_[i].len);
734734
free(defineBuffers_[i].ind);
735735

736-
if ( extDefines_[i] )
736+
if ( extDefines_[i] &&
737+
extDefines_[i]->extDefType == NJS_EXTDEFINE_CLOBASSTR )
737738
{
738739
free ( extDefines_[i]->fields.extClobAsStr.ctx ) ;
740+
free ( extDefines_[i]->fields.extClobAsStr.len2 ) ;
739741
delete ( extDefines_[i] );
740742
}
741743
extDefines_.resize ( 0 ) ;

0 commit comments

Comments
 (0)