Skip to content

Commit

Permalink
Don't call avifAlloc,avifFree in apps and examples
Browse files Browse the repository at this point in the history
They can call malloc(), calloc(), realloc(), and free().
  • Loading branch information
wantehchang committed Oct 20, 2023
1 parent 1d51a11 commit fd73737
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apps/avifenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,11 @@ static avifBool readEntireFile(const char * filename, avifRWData * raw)
return AVIF_TRUE;
}

// Returns NULL if a memory allocation failed.
// Returns NULL if a memory allocation failed. The return value should be freed with free().
static char * avifStrdup(const char * str)
{
size_t len = strlen(str);
char * dup = avifAlloc(len + 1);
char * dup = malloc(len + 1);
if (!dup) {
return NULL;
}
Expand Down
6 changes: 2 additions & 4 deletions examples/avif_example_decode_streaming.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// This example intends to show how a custom avifIO implementation can be used to decode
// partially-downloaded AVIFs. Read either the avif_example_decode_file or
Expand Down Expand Up @@ -91,16 +90,15 @@ static avifResult avifIOStreamingReaderRead(struct avifIO * io, uint32_t readFla

static void avifIOStreamingReaderDestroy(struct avifIO * io)
{
avifFree(io);
free(io);
}

// Returns null in case of memory allocation failure.
static avifIOStreamingReader * avifIOCreateStreamingReader(const uint8_t * data, size_t size)
{
avifIOStreamingReader * reader = avifAlloc(sizeof(avifIOStreamingReader));
avifIOStreamingReader * reader = calloc(1, sizeof(avifIOStreamingReader));
if (!reader)
return NULL;
memset(reader, 0, sizeof(avifIOStreamingReader));

// It is legal for io.destroy to be NULL, in which you are responsible for cleaning up
// your own reader. This allows for a pre-existing, on-the-stack, or member variable to be
Expand Down

0 comments on commit fd73737

Please sign in to comment.