diff --git a/hdrcache.c b/hdrcache.c index 5bcef1a..9c086ad 100644 --- a/hdrcache.c +++ b/hdrcache.c @@ -117,9 +117,9 @@ Header hdrcache_get(const char *path, const struct stat *st, unsigned *off) mcdb_put(env, key, keysize, data, datasize); } void *blob = data->blob; + int blobsize = datasize - sizeof(struct cache_ent) + 1; char ublob[hdrsize_max]; if (data->vflags & V_LZO) { - int blobsize = datasize - sizeof(struct cache_ent) + 1; lzo_uint ublobsize = 0; int rc = lzo1x_decompress(blob, blobsize, ublob, &ublobsize, NULL); if (rc != LZO_E_OK || ublobsize < 1 || ublobsize > hdrsize_max) { @@ -127,14 +127,16 @@ Header hdrcache_get(const char *path, const struct stat *st, unsigned *off) return NULL; } blob = ublob; + blobsize = ublobsize; } - Header h = headerLoad(blob); + Header h = headerCopyLoad(blob); if (h == NULL) { fprintf(stderr, "%s %s: headerLoad failed\n", __func__, key); return NULL; } if (off) *off = data->off; + free(data); return h; }