Skip to content

Commit a4def2a

Browse files
committed
Fix memleak in Hash and bug in devp2p Packet creation
Signed-off-by: Luis Pinto <luis.pinto@consensys.net>
1 parent 10e6e81 commit a4def2a

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

crypto/src/main/java/org/apache/tuweni/v2/crypto/Hash.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static byte[] sha2_256(byte[] input) {
104104
try {
105105
SHA256Hash.Hash result = SHA256Hash.hash(shaInput);
106106
try {
107-
return SHA256Hash.hash(shaInput).bytesArray();
107+
return result.bytesArray();
108108
} finally {
109109
result.destroy();
110110
}
@@ -131,7 +131,7 @@ public static Bytes sha2_256(Bytes input) {
131131
try {
132132
SHA256Hash.Hash result = SHA256Hash.hash(shaInput);
133133
try {
134-
return SHA256Hash.hash(shaInput).bytes();
134+
return result.bytes();
135135
} finally {
136136
result.destroy();
137137
}

devp2p/src/main/kotlin/org/apache/tuweni/devp2p/Packet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ internal class ENRRequestPacket private constructor(
398398
fun create(keyPair: SECP256K1.KeyPair, now: Long): Packet {
399399
val expiration = expirationFor(now)
400400
val sigHash = createSignature(
401-
PacketType.ENRRESPONSE,
401+
PacketType.ENRREQUEST,
402402
keyPair,
403403
) { writer ->
404404
encodeTo(writer, expiration)

devp2p/src/main/kotlin/org/apache/tuweni/v2/devp2p/Packet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ internal class ENRRequestPacket private constructor(
397397
fun create(keyPair: SECP256K1.KeyPair, now: Long): Packet {
398398
val expiration = expirationFor(now)
399399
val sigHash = createSignature(
400-
PacketType.ENRRESPONSE,
400+
PacketType.ENRREQUEST,
401401
keyPair,
402402
) { writer ->
403403
encodeTo(writer, expiration)

0 commit comments

Comments
 (0)