Skip to content

Commit 4aabadb

Browse files
committed
Fixed Memory leak while running PL/SQL function returning Objects in a loop (Issue #1711)
1 parent 60f3cd5 commit 4aabadb

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

doc/src/release_notes.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ node-oracledb `v6.7.1 <https://github.com/oracle/node-oracledb/compare/v6.7.0...
1414
Common Changes
1515
++++++++++++++
1616

17-
#) Fixed the issue causing segmentation fault while getting connection from
17+
#) Fixed the issue causing segmentation fault while getting connection from
1818
pool for external authentication.
1919

2020
#) Fixed SyntaxError with Bun runtime.
@@ -50,6 +50,12 @@ Thin Mode Changes
5050
#) Fixed bug with associative arrays indexed by integers that caused the
5151
:meth:`dbObject.getPrevIndex()` method to change the array order.
5252

53+
Thick Mode changes
54+
++++++++++++++++++
55+
56+
#) Fixed Memory leak while running PL/SQL function returning Objects in a loop.
57+
See `Issue #1711 <https://github.com/oracle/node-oracledb/issues/1711>`__.
58+
5359
node-oracledb `v6.7.0 <https://github.com/oracle/node-oracledb/compare/v6.6.0...v6.7.0>`__ (18 Nov 2024)
5460
---------------------------------------------------------------------------------------------------------
5561

lib/connection.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,11 @@ class Connection extends EventEmitter {
748748
}
749749

750750
delete this._impl;
751+
if (!this.thin) {
752+
for (const cls of this._dbObjectClasses.values()) {
753+
cls._objType.refCleanup();
754+
}
755+
}
751756
this._dbObjectClasses.clear();
752757
this.emit('_afterConnClose');
753758
}

src/njsDbObject.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ static bool njsDbObjectType_populateTypeInfo(njsDataTypeInfo *info,
110110
njsBaton *baton, napi_env env, dpiDataTypeInfo *sourceInfo);
111111
static bool njsDbObject_wrap(napi_env env, napi_value value,
112112
njsDbObject **obj);
113+
static napi_value njsDbObjectType_refCleanup(napi_env env,
114+
napi_callback_info info);
113115

114116

115117
//-----------------------------------------------------------------------------
@@ -188,6 +190,7 @@ static void njsDbObject_finalize(napi_env env, void *finalizeData,
188190
dpiObject_release(obj->handle);
189191
obj->handle = NULL;
190192
}
193+
obj->type = NULL;
191194
free(obj);
192195
}
193196

@@ -877,6 +880,21 @@ static void njsDbObjectType_finalize(napi_env env, void *finalizeData,
877880
free(type);
878881
}
879882

883+
//-----------------------------------------------------------------------------
884+
// njsDbObjectType_refCleanup()
885+
// Invoked when njsDbObjectType reference count needs to be decremented.
886+
// This is required for the clean up of obj type reference created
887+
// in njsDbObjectType_populate.
888+
//-----------------------------------------------------------------------------
889+
static napi_value njsDbObjectType_refCleanup(napi_env env,
890+
napi_callback_info info)
891+
{
892+
njsDbObjectType *type;
893+
894+
napi_get_cb_info(env, info, NULL, NULL, NULL, (void**) &type);
895+
NJS_DELETE_REF_AND_CLEAR(type->jsDbObjectType);
896+
return NULL;
897+
}
880898

881899
//-----------------------------------------------------------------------------
882900
// njsDbObjectType_populate()
@@ -995,6 +1013,11 @@ static bool njsDbObjectType_populate(njsDbObjectType *objType,
9951013
NJS_CHECK_NAPI(env, napi_set_named_property(env, jsObjectType,
9961014
"isCollection", temp))
9971015

1016+
// cleanup function
1017+
NJS_CHECK_NAPI(env, napi_create_function(env, "refCleanup", NAPI_AUTO_LENGTH,
1018+
njsDbObjectType_refCleanup, objType, &temp))
1019+
NJS_CHECK_NAPI(env, napi_set_named_property(env, jsObjectType, "refCleanup",
1020+
temp))
9981021
return true;
9991022
}
10001023

0 commit comments

Comments
 (0)