You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/hashtable: Combine allocations
Reviewed-by: Emma Worley <emma@emma.gg> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -37,7 +37,7 @@ struct FFHashtableContext {
|
|||||||
size_t nb_entries;
|
size_t nb_entries;
|
||||||
const AVCRC *crc;
|
const AVCRC *crc;
|
||||||
uint8_t *table;
|
uint8_t *table;
|
||||||
uint8_t *swapbuf;
|
uint8_t swapbuf[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -59,10 +59,11 @@ int ff_hashtable_alloc(struct FFHashtableContext **ctx, size_t key_size, size_t
|
|||||||
const size_t keyval_size = key_size + val_size;
|
const size_t keyval_size = key_size + val_size;
|
||||||
|
|
||||||
if (keyval_size < key_size || // did (unsigned,defined) wraparound happen?
|
if (keyval_size < key_size || // did (unsigned,defined) wraparound happen?
|
||||||
keyval_size > SIZE_MAX - sizeof(size_t) - (ALIGN - 1))
|
keyval_size > FFMIN(SIZE_MAX - sizeof(size_t) - (ALIGN - 1),
|
||||||
|
(SIZE_MAX - sizeof(FFHashtableContext)) / 2))
|
||||||
return AVERROR(ERANGE);
|
return AVERROR(ERANGE);
|
||||||
|
|
||||||
FFHashtableContext *res = av_mallocz(sizeof(*res));
|
FFHashtableContext *res = av_mallocz(sizeof(*res) + 2 * keyval_size);
|
||||||
if (!res)
|
if (!res)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
res->key_size = key_size;
|
res->key_size = key_size;
|
||||||
@ -81,11 +82,6 @@ int ff_hashtable_alloc(struct FFHashtableContext **ctx, size_t key_size, size_t
|
|||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
res->swapbuf = av_calloc(2, res->key_size + res->val_size);
|
|
||||||
if (!res->swapbuf) {
|
|
||||||
ff_hashtable_freep(&res);
|
|
||||||
return AVERROR(ENOMEM);
|
|
||||||
}
|
|
||||||
*ctx = res;
|
*ctx = res;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -208,7 +204,6 @@ void ff_hashtable_freep(struct FFHashtableContext **ctx)
|
|||||||
{
|
{
|
||||||
if (*ctx) {
|
if (*ctx) {
|
||||||
av_freep(&(*ctx)->table);
|
av_freep(&(*ctx)->table);
|
||||||
av_freep(&(*ctx)->swapbuf);
|
|
||||||
}
|
}
|
||||||
av_freep(ctx);
|
av_freep(ctx);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user