35
35
#include "cborinternal_p.h"
36
36
#include "compilersupport_p.h"
37
37
#include "cborinternal_p.h"
38
+ #include <memory.h>
38
39
39
40
#include <inttypes.h>
40
41
#include <stdio.h>
@@ -179,7 +180,7 @@ static CborError dump_bytestring_base16(char **result, CborValue *it)
179
180
return err ;
180
181
181
182
/* a Base16 (hex) output is twice as big as our buffer */
182
- buffer = (uint8_t * )malloc (n * 2 + 1 );
183
+ buffer = (uint8_t * )cbor_malloc (n * 2 + 1 );
183
184
if (buffer == NULL )
184
185
/* out of memory */
185
186
return CborErrorOutOfMemory ;
@@ -209,7 +210,7 @@ static CborError generic_dump_base64(char **result, CborValue *it, const char al
209
210
210
211
/* a Base64 output (untruncated) has 4 bytes for every 3 in the input */
211
212
size_t len = (n + 5 ) / 3 * 4 ;
212
- buffer = (uint8_t * )malloc (len + 1 );
213
+ buffer = (uint8_t * )cbor_malloc (len + 1 );
213
214
if (buffer == NULL )
214
215
/* out of memory */
215
216
return CborErrorOutOfMemory ;
@@ -395,7 +396,7 @@ static CborError tagged_value_to_json(FILE *out, CborValue *it, int flags, Conve
395
396
if (err )
396
397
return err ;
397
398
err = fprintf (out , "\"%s%s\"" , pre , str ) < 0 ? CborErrorIO : CborNoError ;
398
- free (str );
399
+ cbor_free (str );
399
400
status -> flags = TypeWasNotNative | TypeWasTagged | CborByteStringType ;
400
401
return err ;
401
402
}
@@ -467,7 +468,7 @@ static CborError map_to_json(FILE *out, CborValue *it, int flags, ConversionStat
467
468
468
469
/* first, print the key */
469
470
if (fprintf (out , "\"%s\":" , key ) < 0 ) {
470
- free (key );
471
+ cbor_free (key );
471
472
return CborErrorIO ;
472
473
}
473
474
@@ -489,7 +490,7 @@ static CborError map_to_json(FILE *out, CborValue *it, int flags, ConversionStat
489
490
}
490
491
}
491
492
492
- free (key );
493
+ cbor_free (key );
493
494
if (err )
494
495
return err ;
495
496
}
@@ -568,7 +569,7 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
568
569
if (err )
569
570
return err ;
570
571
err = (fprintf (out , "\"%s\"" , str ) < 0 ) ? CborErrorIO : CborNoError ;
571
- free (str );
572
+ cbor_free (str );
572
573
return err ;
573
574
}
574
575
0 commit comments