nghttpx: Fix potential memory leak

This commit is contained in:
Tatsuhiro Tsujikawa 2018-02-03 18:21:42 +09:00
parent 0bb1540682
commit ff3edc09ed
1 changed files with 2 additions and 1 deletions

View File

@ -1934,6 +1934,8 @@ StringRef get_x509_name(BlockAllocator &balloc, X509_NAME *nm) {
return StringRef{};
}
auto b_deleter = defer(BIO_free, b);
// Not documented, but it seems that X509_NAME_print_ex returns the
// number of bytes written into b.
auto slen = X509_NAME_print_ex(b, nm, 0, XN_FLAG_RFC2253);
@ -1943,7 +1945,6 @@ StringRef get_x509_name(BlockAllocator &balloc, X509_NAME *nm) {
auto iov = make_byte_ref(balloc, slen + 1);
BIO_read(b, iov.base, slen);
BIO_free(b);
iov.base[slen] = '\0';
return StringRef{iov.base, static_cast<size_t>(slen)};
}