Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit 8cd7e2d

Browse files
authored
Memory leak fix (#18)
* Fixed memory leak #15 #16 * Update pom.xml Co-authored-by: Katsute <[email protected]>
1 parent 12e589d commit 8cd7e2d

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.kttdevelopment</groupId>
88
<artifactId>simplehttpserver</artifactId>
9-
<version>DEVELOPMENT</version>
9+
<version>03.00.01</version>
1010
<packaging>jar</packaging>
1111

1212
<dependencies>

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpExchangeImpl.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ static SimpleHttpExchange createSimpleHttpExchange(final HttpExchange exchange){
122122

123123
//
124124
String OUT;
125-
final InputStream IN = httpExchange.getRequestBody();
126125

127-
try(final Scanner scanner = new Scanner(IN,StandardCharsets.UTF_8)){
126+
try(InputStream IN = httpExchange.getRequestBody(); final Scanner scanner = new Scanner(IN, StandardCharsets.UTF_8)){
128127
OUT = scanner.useDelimiter("\\A").next();
129-
IN.close();
130-
}catch(IOException | NoSuchElementException e){
128+
}catch(final IOException | NoSuchElementException ignored){
131129
OUT = null;
132130
}
133131

@@ -361,14 +359,17 @@ public void send(final byte[] response, final int responseCode, final boolean gz
361359
exchange.getResponseHeaders().set("Content-Encoding","gzip");
362360
exchange.getResponseHeaders().set("Connection","keep-alive");
363361
sendResponseHeaders(responseCode, 0);
364-
GZIPOutputStream OUT = new GZIPOutputStream(exchange.getResponseBody());
365-
OUT.write(response);
366-
OUT.finish();
362+
try(GZIPOutputStream OUT = new GZIPOutputStream(exchange.getResponseBody())){
363+
OUT.write(response);
364+
OUT.finish();
365+
OUT.flush();
366+
}
367367
}else{
368368
sendResponseHeaders(responseCode,response.length);
369-
final OutputStream OUT = exchange.getResponseBody();
370-
OUT.write(response);
371-
OUT.flush();
369+
try(final OutputStream OUT = exchange.getResponseBody()){
370+
OUT.write(response);
371+
OUT.flush();
372+
}
372373
}
373374
}
374375

0 commit comments

Comments
 (0)