Slightly simplify SSLBuffer
We really don't need buf_allocated, buf_ already can't move
forward or anything strange since free() is called on it.
Change-Id: I05cf6fa4a6c7b252b64e1cbe5885d29d17d8cddb
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/74187
Auto-Submit: Bob Beck <bbe@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
diff --git a/ssl/internal.h b/ssl/internal.h
index eab3af7..7dc522d 100644
--- a/ssl/internal.h
+++ b/ssl/internal.h
@@ -1682,9 +1682,6 @@
uint16_t cap_ = 0;
// inline_buf_ is a static buffer for short reads.
uint8_t inline_buf_[SSL3_RT_HEADER_LENGTH];
- // buf_allocated_ is true if |buf_| points to allocated data and must be freed
- // or false if it points into |inline_buf_|.
- bool buf_allocated_ = false;
};
// ssl_read_buffer_extend_to extends the read buffer to the desired length. For
diff --git a/ssl/ssl_buffer.cc b/ssl/ssl_buffer.cc
index ddd39eb..76c74e2 100644
--- a/ssl/ssl_buffer.cc
+++ b/ssl/ssl_buffer.cc
@@ -37,11 +37,10 @@
"SSL3_ALIGN_PAYLOAD must be a power of 2");
void SSLBuffer::Clear() {
- if (buf_allocated_) {
+ if (buf_ != inline_buf_) {
free(buf_); // Allocated with malloc().
}
buf_ = nullptr;
- buf_allocated_ = false;
offset_ = 0;
size_ = 0;
cap_ = 0;
@@ -58,13 +57,11 @@
}
uint8_t *new_buf;
- bool new_buf_allocated;
size_t new_offset;
if (new_cap <= sizeof(inline_buf_)) {
// This function is called twice per TLS record, first for the five-byte
// header. To avoid allocating twice, use an inline buffer for short inputs.
new_buf = inline_buf_;
- new_buf_allocated = false;
new_offset = 0;
} else {
// Add up to |SSL3_ALIGN_PAYLOAD| - 1 bytes of slack for alignment.
@@ -77,7 +74,6 @@
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return false;
}
- new_buf_allocated = true;
// Offset the buffer such that the record body is aligned.
new_offset =
@@ -88,12 +84,11 @@
// may alias.
OPENSSL_memmove(new_buf + new_offset, buf_ + offset_, size_);
- if (buf_allocated_) {
+ if (buf_ != inline_buf_) {
free(buf_); // Allocated with malloc().
}
buf_ = new_buf;
- buf_allocated_ = new_buf_allocated;
offset_ = new_offset;
cap_ = new_cap;
return true;