Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 481929c

Browse files
committed
Avoids object creation for dead references when solving #113
Signed-off-by: ncordon <[email protected]>
1 parent b754be3 commit 481929c

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/main/native/org_bblfsh_client_v2_libuast_Libuast.cc

+8-7
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class Node : public uast::Node<Node *> {
365365
jobject val =
366366
ObjectMethod(env, "valueAt", METHOD_JNODE_VALUE_AT, CLS_JNODE, obj, i);
367367
// TODO(#113) investigate, it looks like a potential memory leak
368-
return lookupOrCreate(env->NewGlobalRef(val)); // new ref
368+
return lookupOrCreate(val); // borrows the reference
369369
}
370370

371371
void SetValue(size_t i, Node *val) {
@@ -430,12 +430,13 @@ class Interface : public uast::NodeCreator<Node *> {
430430
Node *lookupOrCreate(jobject obj) {
431431
if (!obj) return nullptr;
432432

433-
Node *node = obj2node[obj];
434-
if (node) return node;
435-
436-
node = new Node(this, obj);
437-
obj2node[node->obj] = node;
438-
return node;
433+
if (obj2node.count(obj) > 0) {
434+
return obj2node[obj];
435+
} else {
436+
Node* node = new Node(this, obj);
437+
obj2node[node->obj] = node;
438+
return node;
439+
}
439440
}
440441

441442
// create makes a new object with a specified kind.

0 commit comments

Comments
 (0)