Skip to content

Commit 75eaa19

Browse files
Andy Huffmanthiagomacieira
authored andcommitted
Facilitate replacement of standard library memory management functions
1 parent e27261e commit 75eaa19

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/cborparser_dup_string.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434

3535
#include "cbor.h"
3636
#include "compilersupport_p.h"
37-
#include <stdlib.h>
37+
38+
#if defined(CBOR_CUSTOM_ALLOC_INCLUDE)
39+
# include CBOR_CUSTOM_ALLOC_INCLUDE
40+
#else
41+
# include <stdlib.h>
42+
# define cbor_malloc malloc
43+
# define cbor_free free
44+
#endif
3845

3946
/**
4047
* \fn CborError cbor_value_dup_text_string(const CborValue *value, char **buffer, size_t *buflen, CborValue *next)
@@ -105,14 +112,14 @@ CborError _cbor_value_dup_string(const CborValue *value, void **buffer, size_t *
105112
return err;
106113

107114
++*buflen;
108-
*buffer = malloc(*buflen);
115+
*buffer = cbor_malloc(*buflen);
109116
if (!*buffer) {
110117
/* out of memory */
111118
return CborErrorOutOfMemory;
112119
}
113120
err = _cbor_value_copy_string(value, *buffer, buflen, next);
114121
if (err) {
115-
free(*buffer);
122+
cbor_free(*buffer);
116123
return err;
117124
}
118125
return CborNoError;

0 commit comments

Comments
 (0)