Skip to content

Commit d090244

Browse files
author
heavyrian2012
committed
解决可能内存泄漏的问题
1 parent 22708ca commit d090244

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

broker/src/main/java/io/moquette/spi/impl/Qos1PublishHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,17 @@ void imHandler(String clientID, String fromUser, String topic, byte[] payloadCon
165165
if (session != null && session.getUsername().equals(fromUser)) {
166166
if (data.length > 7*1024 && session.getMqttVersion().protocolLevel() >= MqttVersion.Wildfire_1.protocolLevel()) {
167167
ByteArrayOutputStream out = new ByteArrayOutputStream();
168-
GZIPOutputStream gzip;
168+
GZIPOutputStream gzip = null;
169169
try {
170170
gzip = new GZIPOutputStream(out);
171171
gzip.write(data);
172-
gzip.close();
173172
} catch (Exception e) {
174173
e.printStackTrace();
175174
Utility.printExecption(LOG, e);
175+
} finally {
176+
if(gzip != null) {
177+
gzip.close();
178+
}
176179
}
177180
data = out.toByteArray();
178181
code = (byte)ErrorCode.ERROR_CODE_SUCCESS_GZIPED.code;

0 commit comments

Comments
 (0)