Home | History | Annotate | Download | only in pool

Lines Matching refs:buf

20 #include <openssl/buf.h>
29 static uint32_t CRYPTO_BUFFER_hash(const CRYPTO_BUFFER *buf) {
30 return OPENSSL_hash32(buf->data, buf->len);
94 CRYPTO_BUFFER *const buf = OPENSSL_malloc(sizeof(CRYPTO_BUFFER));
95 if (buf == NULL) {
98 OPENSSL_memset(buf, 0, sizeof(CRYPTO_BUFFER));
100 buf->data = BUF_memdup(data, len);
101 if (len != 0 && buf->data == NULL) {
102 OPENSSL_free(buf);
106 buf->len = len;
107 buf->references = 1;
110 return buf;
113 buf->pool = pool;
116 CRYPTO_BUFFER *duplicate = lh_CRYPTO_BUFFER_retrieve(pool->bufs, buf);
120 inserted = lh_CRYPTO_BUFFER_insert(pool->bufs, &old, buf);
128 // We raced to insert |buf| into the pool and lost, or else there was an
130 OPENSSL_free(buf->data);
131 OPENSSL_free(buf);
135 return buf;
142 void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf) {
143 if (buf == NULL) {
147 CRYPTO_BUFFER_POOL *const pool = buf->pool;
149 if (CRYPTO_refcount_dec_and_test_zero(&buf->references)) {
153 OPENSSL_free(buf->data);
154 OPENSSL_free(buf);
161 if (!CRYPTO_refcount_dec_and_test_zero(&buf->references)) {
162 CRYPTO_MUTEX_unlock_write(&buf->pool->lock);
170 void *found = lh_CRYPTO_BUFFER_delete(pool->bufs, buf);
172 assert(found == buf);
174 CRYPTO_MUTEX_unlock_write(&buf->pool->lock);
175 OPENSSL_free(buf->data);
176 OPENSSL_free(buf);
179 int CRYPTO_BUFFER_up_ref(CRYPTO_BUFFER *buf) {
180 // This is safe in the case that |buf->pool| is NULL because it's just
183 // This is also safe if |buf->pool| is non-NULL because, if it were racing
186 CRYPTO_refcount_inc(&buf->references);
190 const uint8_t *CRYPTO_BUFFER_data(const CRYPTO_BUFFER *buf) {
191 return buf->data;
194 size_t CRYPTO_BUFFER_len(const CRYPTO_BUFFER *buf) {
195 return buf->len;
198 void CRYPTO_BUFFER_init_CBS(const CRYPTO_BUFFER *buf, CBS *out) {
199 CBS_init(out, buf->data, buf->len);