GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Avoid leak in PemReader on OutOfDirectMemoryError (#16… · netty/netty@bf8e056

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler/src/main/java/io/netty/handler/ssl
    • PemReader.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/PemReader.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/PemReader.java
+46-34Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,34 +68,44 @@ static ByteBuf[] readCertificates(InputStream in) throws CertificateException {
6868
List<ByteBuf> certs = new ArrayList<ByteBuf>();
6969
Matcher m = CERT_HEADER.matcher(content);
7070
int start = 0;
71-
for (;;) {
72-
if (!m.find(start)) {
73-
break;
74-
}
75-
76-
// Here and below it's necessary to save the position as it is reset
77-
// after calling usePattern() on Android due to a bug.
78-
//
79-
// See https://issuetracker.google.com/issues/293206296
80-
start = m.end();
81-
m.usePattern(BODY);
82-
if (!m.find(start)) {
83-
break;
71+
try {
72+
for (;;) {
73+
if (!m.find(start)) {
74+
break;
75+
}
76+
77+
// Here and below it's necessary to save the position as it is reset
78+
// after calling usePattern() on Android due to a bug.
79+
//
80+
// See https://issuetracker.google.com/issues/293206296
81+
start = m.end();
82+
m.usePattern(BODY);
83+
if (!m.find(start)) {
84+
break;
85+
}
86+
87+
ByteBuf base64 = Unpooled.copiedBuffer(m.group(0), CharsetUtil.US_ASCII);
88+
try {
89+
start = m.end();
90+
m.usePattern(CERT_FOOTER);
91+
if (!m.find(start)) {
92+
// Certificate is incomplete.
93+
break;
94+
}
95+
ByteBuf der = Base64.decode(base64);
96+
certs.add(der);
97+
} finally {
98+
base64.release();
99+
}
100+
101+
start = m.end();
102+
m.usePattern(CERT_HEADER);
84103
}
85-
86-
ByteBuf base64 = Unpooled.copiedBuffer(m.group(0), CharsetUtil.US_ASCII);
87-
start = m.end();
88-
m.usePattern(CERT_FOOTER);
89-
if (!m.find(start)) {
90-
// Certificate is incomplete.
91-
break;
104+
} catch (Throwable e) {
105+
for (ByteBuf cert : certs) {
106+
cert.release();
92107
}
93-
ByteBuf der = Base64.decode(base64);
94-
base64.release();
95-
certs.add(der);
96-
97-
start = m.end();
98-
m.usePattern(CERT_HEADER);
108+
throw e;
99109
}
100110

101111
if (certs.isEmpty()) {
@@ -132,15 +142,17 @@ static ByteBuf readPrivateKey(InputStream in) throws KeyException {
132142
}
133143

134144
ByteBuf base64 = Unpooled.copiedBuffer(m.group(0), CharsetUtil.US_ASCII);
135-
start = m.end();
136-
m.usePattern(KEY_FOOTER);
137-
if (!m.find(start)) {
138-
// Key is incomplete.
139-
throw keyNotFoundException();
145+
try {
146+
start = m.end();
147+
m.usePattern(KEY_FOOTER);
148+
if (!m.find(start)) {
149+
// Key is incomplete.
150+
throw keyNotFoundException();
151+
}
152+
return Base64.decode(base64);
153+
} finally {
154+
base64.release();
140155
}
141-
ByteBuf der = Base64.decode(base64);
142-
base64.release();
143-
return der;
144156
}
145157

146158
private static KeyException keyNotFoundException() {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.