Changeset 3063:955233719a84 in roaraudio for libroardsp/convert.c


Ignore:
Timestamp:
12/26/09 20:36:31 (14 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

use memory functions from libroar, not libc, fixed a small memory leak

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroardsp/convert.c

    r2797 r3063  
    548548 double radio = (double) to / (double) from; 
    549549 int outsamples = radio * samples; 
    550  float * inf  = malloc(samples*sizeof(float)); 
    551  float * outf = malloc(outsamples*sizeof(float)); 
     550 float * inf  = roar_mm_malloc(samples*sizeof(float)); 
     551 float * outf = roar_mm_malloc(outsamples*sizeof(float)); 
    552552 int i; 
    553553 SRC_DATA srcdata; 
     
    557557 if ( inf == NULL ) { 
    558558  if ( outf != NULL ) 
    559    free(outf); 
     559   roar_mm_free(outf); 
    560560 
    561561  return -1; 
     
    564564 if ( outf == NULL ) { 
    565565  if ( inf != NULL ) 
    566    free(inf); 
     566   roar_mm_free(inf); 
    567567 
    568568  return -1; 
     
    583583   break; 
    584584  default: 
    585     free(outf); 
    586     free(inf); 
     585    roar_mm_free(outf); 
     586    roar_mm_free(inf); 
    587587    return -1; 
    588588 } 
     
    595595 
    596596 if ( src_simple(&srcdata, SRC_ZERO_ORDER_HOLD, channels) != 0 ) { 
    597   free(outf); 
    598   free(inf); 
     597  roar_mm_free(outf); 
     598  roar_mm_free(inf); 
    599599  return -1; 
    600600 } 
     
    616616 } 
    617617 
    618  free(outf); 
    619  free(inf); 
     618 roar_mm_free(outf); 
     619 roar_mm_free(inf); 
    620620 
    621621 return 0; 
     
    883883  real_out = out; 
    884884 
    885   if ( (out = malloc(from_size)) == NULL ) 
    886    return -1; 
    887  
    888   ROAR_DBG("roar_conv(*): malloc(%i)=%p", (int)from_size, out); 
     885  if ( (out = roar_mm_malloc(from_size)) == NULL ) 
     886   return -1; 
     887 
     888  ROAR_DBG("roar_conv(*): roar_mm_malloc(%i)=%p", (int)from_size, out); 
    889889 } 
    890890 
     
    895895  if ( roar_conv_endian(out, ip, samples, ROAR_CODEC_BYTE_ORDER(from->codec), ROAR_CODEC_NATIVE_ENDIAN, from->bits) == -1 ) { 
    896896   if ( to_size < from_size ) 
    897     free(out); 
     897    roar_mm_free(out); 
    898898   return -1; 
    899899  } else { 
     
    905905  if ( roar_conv_bits(out, ip, samples, from->bits, to->bits) == -1 ) { 
    906906   if ( to_size < from_size ) 
    907     free(out); 
     907    roar_mm_free(out); 
    908908   return -1; 
    909909  } else { 
     
    915915  if ( roar_conv_signedness(out, ip, samples, ROAR_CODEC_IS_SIGNED(from->codec), ROAR_CODEC_IS_SIGNED(to->codec), to->bits) == -1 ) { 
    916916   if ( to_size < from_size ) 
    917     free(out); 
     917    roar_mm_free(out); 
    918918   return -1; 
    919919  } else { 
     
    935935   ROAR_DBG("roar_conv(*): failed to convert rate %i->%i (%ich%ibits)", from->rate, to->rate, to->bits, from->channels); 
    936936   if ( to_size < from_size ) 
    937     free(out); 
     937    roar_mm_free(out); 
    938938   return -1; 
    939939  } else { 
     
    946946  if ( roar_conv_chans(out, ip, samples, from->channels, to->channels, to->bits) == -1 ) { 
    947947   if ( to_size < from_size ) 
    948     free(out); 
     948    roar_mm_free(out); 
    949949   return -1; 
    950950  } else { 
     
    956956  if ( roar_conv_endian(out, ip, samples, ROAR_CODEC_NATIVE_ENDIAN, ROAR_CODEC_BYTE_ORDER(to->codec), to->bits) == -1 ) { 
    957957   if ( to_size < from_size ) 
    958     free(out); 
     958    roar_mm_free(out); 
    959959   return -1; 
    960960  } else { 
     
    966966  ROAR_DBG("roar_conv(*): memcpy(%p, %p, %i) = ?", real_out, out, (int)to_size); 
    967967  memcpy(real_out, out, to_size); 
    968   free(out); 
     968  roar_mm_free(out); 
    969969  ROAR_DBG("roar_conv(*): free(%p): OK!", out); 
    970970 } 
Note: See TracChangeset for help on using the changeset viewer.