Skip to content

Commit a76c8a7

Browse files
committed
http: compression: brotli: Don't leak memory on error
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
1 parent ff7da85 commit a76c8a7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/nxt_brotli.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,33 @@ nxt_brotli_compress(nxt_http_comp_compressor_ctx_t *ctx, const uint8_t *in_buf,
4646
&in_len, &in_buf, &out_bytes, &out_buf,
4747
NULL);
4848
if (!ok) {
49-
return -1;
49+
goto out_err_free;
5050
}
5151

5252
ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_FLUSH,
5353
&in_len, &in_buf, &out_bytes, &out_buf,
5454
NULL);
5555
if (!ok) {
56-
return -1;
56+
goto out_err_free;
5757
}
5858

5959
if (last) {
6060
ok = BrotliEncoderCompressStream(brotli, BROTLI_OPERATION_FINISH,
6161
&in_len, &in_buf, &out_bytes,
6262
&out_buf, NULL);
6363
if (!ok) {
64-
return -1;
64+
goto out_err_free;
6565
}
6666

6767
BrotliEncoderDestroyInstance(brotli);
6868
}
6969

7070
return out_len - out_bytes;
71+
72+
out_err_free:
73+
BrotliEncoderDestroyInstance(brotli);
74+
75+
return -1;
7176
}
7277

7378

0 commit comments

Comments
 (0)