Skip to content

Commit a13a53a

Browse files
committed
Handle AIX memory allocator differences
1 parent d0551d9 commit a13a53a

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Fixed a [regression](https://github.com/oracle/node-oracledb/issues/1152) when
1212
binding dates with alternative JavaScript frameworks.
1313

14+
- Fixed "NJS-024: memory allocation failed" errors seen on AIX.
15+
1416
- Fixed a JavaScript memory leak when getting Oracle Database named type
1517
information, such as with `getDbObjectClass()`.
1618

src/njsAqQueue.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ static bool njsAqQueue_enqManyProcessArgs(njsBaton *baton,
526526
return njsUtils_throwError(env, errInvalidParameterValue, 1);
527527
NJS_CHECK_NAPI(env, napi_get_array_length(env, args[0],
528528
&baton->numMsgProps))
529+
if (baton->numMsgProps == 0)
530+
return njsUtils_throwError(env, errInvalidParameterValue, 1);
529531
baton->msgProps = calloc(baton->numMsgProps, sizeof(dpiMsgProps*));
530532
if (!baton->msgProps)
531533
return njsBaton_setError(baton, errInsufficientMemory);

src/njsBaton.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ bool njsBaton_getFetchInfoFromArg(njsBaton *baton, napi_env env,
458458
// allocate space for the fetchInfo based on the number of keys
459459
NJS_CHECK_NAPI(env, napi_get_array_length(env, keys, &numElements))
460460
tempFetchInfo = calloc(numElements, sizeof(njsFetchInfo));
461-
if (!tempFetchInfo)
461+
if (!tempFetchInfo && numElements > 0)
462462
return njsBaton_setError(baton, errInsufficientMemory);
463463
*numFetchInfo = numElements;
464464
*fetchInfo = tempFetchInfo;
@@ -628,8 +628,11 @@ bool njsBaton_getStringArrayFromArg(njsBaton *baton, napi_env env,
628628
if (!array)
629629
return true;
630630

631-
// get length of array
631+
// get length of array; if there are no elements in the array, nothing
632+
// further needs to be done
632633
NJS_CHECK_NAPI(env, napi_get_array_length(env, array, &arrayLength))
634+
if (arrayLength == 0)
635+
return true;
633636

634637
// allocate memory for the results
635638
tempStrings = calloc(arrayLength, sizeof(char*));

src/njsConnection.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1873,14 +1873,17 @@ static bool njsConnection_initBindVars(njsBaton *baton, napi_env env,
18731873
njsVariable *var;
18741874
uint32_t i;
18751875

1876-
// determine the numbe of bind variables
1876+
// determine the number of bind variables; if none are provided, nothing
1877+
// further needs to be done
18771878
if (bindNames) {
18781879
NJS_CHECK_NAPI(env, napi_get_array_length(env, bindNames,
18791880
&baton->numBindVars))
18801881
} else {
18811882
NJS_CHECK_NAPI(env, napi_get_array_length(env, binds,
18821883
&baton->numBindVars))
18831884
}
1885+
if (baton->numBindVars == 0)
1886+
return true;
18841887

18851888
// allocate memory for the bind variables
18861889
baton->bindVars = calloc(baton->numBindVars, sizeof(njsVariable));

src/njsUtils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ bool njsUtils_copyArray(napi_env env, void *sourceArray, uint32_t numElements,
274274
bool njsUtils_copyString(napi_env env, char *source, size_t sourceLength,
275275
char **dest, size_t *destLength)
276276
{
277-
if (source) {
277+
if (source && sourceLength > 0) {
278278
*dest = malloc(sourceLength);
279279
if (!*dest)
280280
return njsUtils_throwError(env, errInsufficientMemory);
@@ -765,7 +765,7 @@ bool njsUtils_setPropUnsignedIntArray(napi_env env, napi_value value,
765765
// allocate memory for array, if applicable
766766
NJS_CHECK_NAPI(env, napi_get_array_length(env, value, &numElements))
767767
elements = calloc(numElements, sizeof(uint32_t));
768-
if (!elements)
768+
if (!elements && numElements > 0)
769769
return njsUtils_throwError(env, errInsufficientMemory);
770770

771771
// validate values in the array

src/njsVariable.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,8 @@ static bool njsVariable_processBuffer(njsVariable *var,
768768
case DPI_ORACLE_TYPE_NCLOB:
769769
case DPI_ORACLE_TYPE_BLOB:
770770
NJS_FREE_AND_CLEAR(buffer->lobs);
771+
if (buffer->numElements == 0)
772+
break;
771773
buffer->lobs = calloc(buffer->numElements, sizeof(njsLobBuffer));
772774
if (!buffer->lobs)
773775
return njsBaton_setError(baton, errInsufficientMemory);

0 commit comments

Comments
 (0)