@@ -1185,6 +1185,12 @@ void Connection::GetInBindParamsScalar(Local<Value> v8val, Bind* bind,
11851185 /* This has to be allocated after stmt is initialized */
11861186 bind->dttmarr = NULL ;
11871187 bind->extvalue = (long double *) malloc (sizeof ( long double ) );
1188+ if ( !bind->extvalue )
1189+ {
1190+ executeBaton -> error = NJSMessages::getErrorMsg (
1191+ errInsufficientMemory );
1192+ goto exitGetInBindParamsScalar;
1193+ }
11881194 bind->value = NULL ;
11891195 bind->type = dpi::DpiTimestampLTZ;
11901196 *(bind->len ) = 0 ;
@@ -1478,6 +1484,12 @@ void Connection::GetInBindParamsArray(Local<Array> va8vals, Bind *bind,
14781484 bufferSize = static_cast <size_t >(arrayElementSize *
14791485 bind->maxArraySize );
14801486 buffer = reinterpret_cast <char *>(malloc (bufferSize));
1487+ if ( !buffer )
1488+ {
1489+ executeBaton->error = NJSMessages::getErrorMsg (
1490+ errInsufficientMemory );
1491+ goto exitGetInBindParamsArray;
1492+ }
14811493 bind->value = buffer;
14821494 break ;
14831495
@@ -5373,6 +5385,12 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
53735385 else
53745386 {
53755387 bind->value = (void *)malloc ( (size_t )(bind->maxSize ) * nRows ) ;
5388+ if ( !bind->value )
5389+ {
5390+ executeBaton->error = NJSMessages::getErrorMsg (
5391+ errInsufficientMemory );
5392+ goto exitcbDynBufferAllocate;
5393+ }
53765394 *(bind->len ) = (unsigned int )bind->maxSize ;
53775395 }
53785396 break ;
@@ -5514,7 +5532,7 @@ int Connection::cbDynBufferGet ( void *ctx, DPI_SZ_TYPE nRows,
55145532 rcodepp (INOUT) - pointer to specify return code (NOT USED)
55155533
55165534 RETURNS
5517- -NONE-
5535+ 0 on success and -1 on memory allocation failures.
55185536
55195537 NOTE:
55205538 The callback is called repeteatedly for the same row with iter (0 based)
@@ -5523,7 +5541,7 @@ int Connection::cbDynBufferGet ( void *ctx, DPI_SZ_TYPE nRows,
55235541 is passed to the callback, new set of buffer(s) has to be provided and
55245542 initialized.
55255543*/
5526- void Connection::cbDynDefine ( void *octxp, unsigned long definePos,
5544+ int Connection::cbDynDefine ( void *octxp, unsigned long definePos,
55275545 unsigned long iter, unsigned long *prevIter,
55285546 void **bufpp, unsigned long **alenpp,
55295547 void **indpp, unsigned short **rcodepp )
@@ -5532,6 +5550,8 @@ void Connection::cbDynDefine ( void *octxp, unsigned long definePos,
55325550 Define *define = &(executeBaton->defines [definePos]);
55335551 unsigned long maxLen = 0 ;
55345552 char **buf = (char **)define->buf ;
5553+ char *tmp = NULL ; // to presever ptr for realloc
5554+ int ret = 0 ;
55355555
55365556 if ( *prevIter != iter )
55375557 {
@@ -5545,16 +5565,28 @@ void Connection::cbDynDefine ( void *octxp, unsigned long definePos,
55455565 maxLen = ( ( ( unsigned long ) (**alenpp ) ) + NJS_ITER_SIZE );
55465566 }
55475567
5568+ tmp = buf[iter]; // preserve the current memory address
5569+
55485570 // allocate or reallocate buffer
55495571 buf[iter] = (char *) ( ( !buf[iter] ) ?
55505572 malloc ( maxLen ) : realloc ( buf[iter], maxLen ) ) ;
5573+ if ( !buf[iter] )
5574+ {
5575+ // If realloc fails, the IN parameter requires to be freed and untouched
5576+ // restore the pointer and return error.
5577+ buf[iter] = tmp ;
5578+ ret = -1 ;
5579+ }
5580+ else
5581+ {
5582+ define->len [iter] = maxLen;
5583+ define->ind [iter] = 0 ; // default value for indicator
55515584
5552- define->len [iter] = maxLen;
5553- define->ind [iter] = 0 ; // defalt value for indicator
5554-
5555- *bufpp = (void *) buf[iter]; // memory for this iter
5556- *alenpp = (unsigned long *) &(define->len [iter]) ; // size for this iter
5557- *indpp = (void *) &(define->ind [iter]); // indicator
5585+ *bufpp = (void *) buf[iter]; // memory for this iter
5586+ *alenpp = (unsigned long *) &(define->len [iter]) ; // size for this iter
5587+ *indpp = (void *) &(define->ind [iter]); // indicator
5588+ }
5589+ return ret ;
55585590}
55595591
55605592
0 commit comments