@@ -302,7 +302,7 @@ roaring_buffer_t *roaring_buffer_create(const char *buf, size_t buf_len){
302302 /* make sure keyscards is 2 bytes aligned */
303303 bool keyscards_need_free = false;
304304 if ((uintptr_t )keyscards % sizeof (uint16_t ) != 0 ) {
305- uint16_t * tmpbuf = malloc (size * 2 * sizeof (uint16_t ));
305+ uint16_t * tmpbuf = roaring_malloc (size * 2 * sizeof (uint16_t ));
306306 if (tmpbuf == NULL ) {
307307 fprintf (stderr , "Failed to allocate memory for keyscards. Bailing out.\n" );
308308 return NULL ;
@@ -319,17 +319,17 @@ roaring_buffer_t *roaring_buffer_create(const char *buf, size_t buf_len){
319319 if (readbytes > buf_len ) {// data is corrupted?
320320 fprintf (stderr , "Ran out of bytes while reading offsets.\n" );
321321 if (keyscards_need_free )
322- free (keyscards );
322+ roaring_free (keyscards );
323323 return NULL ;
324324 }
325325
326326 offsets = (uint32_t * )buf ;
327327 if ((uintptr_t )offsets % 4 != 0 ) {
328- uint32_t * tmpbuf = malloc (size * 4 );
328+ uint32_t * tmpbuf = roaring_malloc (size * 4 );
329329 if (tmpbuf == NULL ) {
330330 fprintf (stderr , "Failed to allocate memory for offsets. Bailing out.\n" );
331331 if (keyscards_need_free )
332- free (keyscards );
332+ roaring_free (keyscards );
333333 return NULL ;
334334 }
335335 memcpy (tmpbuf , offsets , size * 4 );
@@ -340,11 +340,11 @@ roaring_buffer_t *roaring_buffer_create(const char *buf, size_t buf_len){
340340 buf += size * 4 ;
341341 }
342342 else {
343- offsets = malloc (size * 4 );
343+ offsets = roaring_malloc (size * 4 );
344344 if (offsets == NULL ) {
345345 fprintf (stderr , "Failed to allocate memory for offsets. Bailing out.\n" );
346346 if (keyscards_need_free )
347- free (keyscards );
347+ roaring_free (keyscards );
348348 return NULL ;
349349 }
350350 offsets_need_free = true;
@@ -371,8 +371,8 @@ roaring_buffer_t *roaring_buffer_create(const char *buf, size_t buf_len){
371371 if (readbytes > buf_len ) {
372372 fprintf (stderr , "Running out of bytes while reading a run container (header).\n" );
373373 if (keyscards_need_free )
374- free (keyscards );
375- free (offsets );
374+ roaring_free (keyscards );
375+ roaring_free (offsets );
376376 return NULL ;
377377 }
378378 uint16_t n_runs ;
@@ -389,13 +389,13 @@ roaring_buffer_t *roaring_buffer_create(const char *buf, size_t buf_len){
389389 }
390390 }
391391
392- roaring_buffer_t * ans = (roaring_buffer_t * )malloc (sizeof (roaring_buffer_t ));
392+ roaring_buffer_t * ans = (roaring_buffer_t * )roaring_malloc (sizeof (roaring_buffer_t ));
393393 if (ans == NULL ) {
394394 fprintf (stderr , "Failed to allocate memory for roaring buffer. Bailing out.\n" );
395395 if (keyscards_need_free )
396- free (keyscards );
396+ roaring_free (keyscards );
397397 if (offsets_need_free )
398- free (offsets );
398+ roaring_free (offsets );
399399 return NULL ;
400400 }
401401
@@ -418,11 +418,11 @@ roaring_buffer_t *roaring_buffer_create(const char *buf, size_t buf_len){
418418 */
419419void roaring_buffer_free (const roaring_buffer_t * rb ) {
420420 if (rb -> keyscards_need_free )
421- free ((void * )rb -> keyscards );
421+ roaring_free ((void * )rb -> keyscards );
422422 if (rb -> offsets_need_free )
423- free ((void * )rb -> offsets );
423+ roaring_free ((void * )rb -> offsets );
424424
425- free ((void * )rb );
425+ roaring_free ((void * )rb );
426426}
427427
428428
0 commit comments