From 99606785a06b710cd4e97f5f3e5464e50d449d72 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 28 Jan 2021 18:23:11 -0500 Subject: [PATCH] Fix leak in manual memory management in PeerTest --- src/test/java/org/ldk/PeerTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 2cabf254..be652d2b 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -5,7 +5,9 @@ import org.bitcoinj.script.Script; import org.junit.jupiter.api.Test; import org.ldk.impl.bindings; import org.ldk.enums.*; +import org.ldk.structs.Result_NoneChannelMonitorUpdateErrZ; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -32,6 +34,7 @@ public class PeerTest { bindings.LDKBroadcasterInterface broad_trait; bindings.LDKLogger log_trait; bindings.LDKWatch watcher; + ArrayList results_to_free; Peer(byte seed) { this.log_trait = (String arg)-> System.out.println(seed + ": " + arg); @@ -41,6 +44,7 @@ public class PeerTest { this.broad_trait = tx -> { // We should broadcast }; + this.results_to_free = new ArrayList<>(); this.tx_broadcaster = bindings.LDKBroadcasterInterface_new(this.broad_trait); this.monitors = new HashMap<>(); this.watcher = new bindings.LDKWatch() { @@ -50,7 +54,9 @@ public class PeerTest { assert monitors.put(Arrays.toString(bindings.OutPoint_get_txid(funding_txo)), monitor) == null; } bindings.OutPoint_free(funding_txo); - return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + long res = bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + results_to_free.add(res); + return res; } @Override @@ -64,7 +70,9 @@ public class PeerTest { } bindings.OutPoint_free(funding_txo); bindings.ChannelMonitorUpdate_free(update); - return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + long res = bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + results_to_free.add(res); + return res; } @Override @@ -142,6 +150,9 @@ public class PeerTest { bindings.ChannelMonitor_free(mon); } } + for (Long res : results_to_free) { + bindings.CResult_NoneChannelMonitorUpdateErrZ_free(res); + } } } -- 2.39.5