Changeset d8d6b1e in mod_gnutls


Ignore:
Timestamp:
Apr 29, 2018, 6:33:34 AM (2 years ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
debian/master, master, proxy-ticket
Children:
f52f1b4
Parents:
a314ec9
Message:

Reallocate buffer to data size after fetching from socache

There is no way to know the size of an socache object before fetching,
so the provided buffer must be large. To avoid wasting memory shrink
the buffer to the actual size of the object after fetching.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_cache.c

    ra314ec9 rd8d6b1e  
    165165
    166166
    167 // 4K should be enough for OCSP responses and sessions alike
    168 #define SOCACHE_FETCH_BUF_SIZE 4096
     167/** 8K is the maximum size accepted when receiving OCSP responses,
     168 * sessions cache entries should be much smaller. The buffer is
     169 * reallocated to actual size after fetching, so memory waste is
     170 * minimal and temporary. */
     171#define SOCACHE_FETCH_BUF_SIZE (8 * 1024)
     172
    169173gnutls_datum_t mgs_cache_fetch(mgs_cache_t cache, server_rec *server,
    170174                               gnutls_datum_t key, apr_pool_t *pool)
     
    212216                     "fetched %u bytes from cache '%s:%s'",
    213217                     data.size, cache->prov->name, sc->cache->config);
     218
     219        /* Realloc buffer to data.size. Data size must be less than or
     220         * equal to the initial buffer size, so this REALLY should not
     221         * fail. */
     222        data.data = gnutls_realloc(data.data, data.size);
     223        if (__builtin_expect(data.data == NULL, 0))
     224        {
     225            ap_log_error(APLOG_MARK, APLOG_CRIT, APR_ENOMEM, server,
     226                         "%s: Could not realloc fetch buffer to data size!",
     227                         __func__);
     228            data.size = 0;
     229        }
    214230    }
    215231    apr_pool_destroy(spool);
Note: See TracChangeset for help on using the changeset viewer.