Fold away clean boolean in BUF_MEM.

OPENSSL_free always zeros things now.

Change-Id: Iaad94f0d7ad51ade05ae89751321314d235d6d67
Reviewed-on: https://boringssl-review.googlesource.com/21384
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2017-10-06 23:53:25 -04:00 committed by CQ bot account: commit-bot@chromium.org
parent 03a4b96c12
commit 2450027e59
2 changed files with 6 additions and 14 deletions

View File

@ -86,7 +86,7 @@ void BUF_MEM_free(BUF_MEM *buf) {
OPENSSL_free(buf); OPENSSL_free(buf);
} }
static int buf_mem_reserve(BUF_MEM *buf, size_t cap, int clean) { int BUF_MEM_reserve(BUF_MEM *buf, size_t cap) {
if (buf->max >= cap) { if (buf->max >= cap) {
return 1; return 1;
} }
@ -116,12 +116,8 @@ static int buf_mem_reserve(BUF_MEM *buf, size_t cap, int clean) {
return 1; return 1;
} }
int BUF_MEM_reserve(BUF_MEM *buf, size_t cap) { size_t BUF_MEM_grow(BUF_MEM *buf, size_t len) {
return buf_mem_reserve(buf, cap, 0 /* don't clear old buffer contents. */); if (!BUF_MEM_reserve(buf, len)) {
}
static size_t buf_mem_grow(BUF_MEM *buf, size_t len, int clean) {
if (!buf_mem_reserve(buf, len, clean)) {
return 0; return 0;
} }
if (buf->length < len) { if (buf->length < len) {
@ -131,12 +127,8 @@ static size_t buf_mem_grow(BUF_MEM *buf, size_t len, int clean) {
return len; return len;
} }
size_t BUF_MEM_grow(BUF_MEM *buf, size_t len) {
return buf_mem_grow(buf, len, 0 /* don't clear old buffer contents. */);
}
size_t BUF_MEM_grow_clean(BUF_MEM *buf, size_t len) { size_t BUF_MEM_grow_clean(BUF_MEM *buf, size_t len) {
return buf_mem_grow(buf, len, 1 /* clear old buffer contents. */); return BUF_MEM_grow(buf, len);
} }
char *BUF_strdup(const char *str) { char *BUF_strdup(const char *str) {

View File

@ -89,8 +89,8 @@ OPENSSL_EXPORT int BUF_MEM_reserve(BUF_MEM *buf, size_t cap);
// zeros. It returns the length of |buf|, or zero if there's an error. // zeros. It returns the length of |buf|, or zero if there's an error.
OPENSSL_EXPORT size_t BUF_MEM_grow(BUF_MEM *buf, size_t len); OPENSSL_EXPORT size_t BUF_MEM_grow(BUF_MEM *buf, size_t len);
// BUF_MEM_grow_clean acts the same as |BUF_MEM_grow|, but clears the previous // BUF_MEM_grow_clean calls |BUF_MEM_grow|. BoringSSL always zeros memory
// contents of memory if reallocing. // allocated memory on free.
OPENSSL_EXPORT size_t BUF_MEM_grow_clean(BUF_MEM *buf, size_t len); OPENSSL_EXPORT size_t BUF_MEM_grow_clean(BUF_MEM *buf, size_t len);
// BUF_strdup returns an allocated, duplicate of |str|. // BUF_strdup returns an allocated, duplicate of |str|.