tools: fix realloc failure handling in midifile ensure_buffer

On realloc failure, the old mf->buffer pointer should be preserverd to avoid memory leaks.
This commit is contained in:
zuozhiwei 2026-04-17 10:04:35 +08:00
parent 61a9c78e1d
commit d4b472d2e5

View file

@ -152,7 +152,12 @@ static uint8_t *ensure_buffer(struct midi_file *mf, struct midi_track *tr, size_
return tr->event;
if (size > mf->buffer_size) {
mf->buffer = realloc(mf->buffer, size);
uint8_t *newbuf = realloc(mf->buffer, size);
if (newbuf == NULL)
return NULL;
mf->buffer = newbuf;
mf->buffer_size = size;
}
return mf->buffer;