Skip to content

Commit bbc424a

Browse files
authored
SNOW-2266612: fix StmtUtil.execute:gzos free memory (#2303)
1 parent 78e3163 commit bbc424a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/main/java/net/snowflake/client/core/StmtUtil.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,14 @@ public static StmtOutput execute(
368368
execTimeData.setGzipStart();
369369
// SNOW-18057: compress the post body in gzip
370370
ByteArrayOutputStream baos = new ByteArrayOutputStream();
371-
GZIPOutputStream gzos = new GZIPOutputStream(baos);
372-
byte[] bytes = json.getBytes("UTF-8");
373-
gzos.write(bytes);
374-
gzos.finish();
375-
input = new ByteArrayEntity(baos.toByteArray());
376-
httpRequest.addHeader("content-encoding", "gzip");
377-
execTimeData.setGzipEnd();
371+
try (GZIPOutputStream gzos = new GZIPOutputStream(baos)) {
372+
byte[] bytes = json.getBytes("UTF-8");
373+
gzos.write(bytes);
374+
gzos.finish();
375+
input = new ByteArrayEntity(baos.toByteArray());
376+
httpRequest.addHeader("content-encoding", "gzip");
377+
execTimeData.setGzipEnd();
378+
}
378379
} else {
379380
input = new ByteArrayEntity(json.getBytes("UTF-8"));
380381
}

0 commit comments

Comments
 (0)