Changeset 3063:955233719a84 in roaraudio


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

Files:
10 edited

Legend:

Unmodified
Added
Removed
  • libroar/stack.c

    r1284 r3063  
    4848 
    4949struct roar_stack * roar_stack_newalloc(void) { 
    50  struct roar_stack * stack = malloc(sizeof(struct roar_stack)); 
     50 struct roar_stack * stack = roar_mm_malloc(sizeof(struct roar_stack)); 
    5151 
    5252 if ( stack == NULL ) 
  • libroar/vio_cmd.c

    r1663 r3063  
    4646  return -1; 
    4747 
    48  if ( (state = malloc(sizeof(struct roar_vio_cmd_state))) == NULL ) 
     48 if ( (state = roar_mm_malloc(sizeof(struct roar_vio_cmd_state))) == NULL ) 
    4949  return -1; 
    5050 
     
    132132 
    133133// state->state = ROAR_VIO_CMD_STATE_CLOSED; 
    134  free(state); 
     134 roar_mm_free(state); 
    135135 
    136136 return 0; 
     
    226226  return -1; 
    227227 
    228  if ( (state = malloc(sizeof(struct roar_vio_2popen_state))) == NULL ) 
     228 if ( (state = roar_mm_malloc(sizeof(struct roar_vio_2popen_state))) == NULL ) 
    229229  return -1; 
    230230 
     
    282282  free(state->child.cmd); 
    283283 
    284  free(state); 
     284 roar_mm_free(state); 
    285285 
    286286 return 0; 
  • libroar/vio_pipe.c

    r1505 r3063  
    4343  return -1; 
    4444 
    45  if ( (self = malloc(sizeof(struct roar_vio_pipe))) == NULL ) 
     45 if ( (self = roar_mm_malloc(sizeof(struct roar_vio_pipe))) == NULL ) 
    4646  return -1; 
    4747 
     
    6565    // no buffers need to be set up here, 
    6666    // we handle the NULL pointer in the reader and writer func 
    67     free(self); 
     67    roar_mm_free(self); 
    6868    return -1; 
    6969   break; 
     
    7373    if ( rw == O_RDWR || rw == O_RDONLY ) 
    7474     if ( pipe(self->b.p) == -1 ) { 
    75       free(self); 
     75      roar_mm_free(self); 
    7676      return -1; 
    7777     } 
     
    8080      close(self->b.p[0]); 
    8181      close(self->b.p[1]); 
    82       free(self); 
     82      roar_mm_free(self); 
    8383      return -1; 
    8484     } 
     
    8686  case ROAR_VIO_PIPE_TYPE_SOCKET: 
    8787    if ( socketpair(AF_UNIX, SOCK_STREAM, 0, self->b.p) == -1 ) { 
    88      free(self); 
     88     roar_mm_free(self); 
    8989     return -1; 
    9090    } 
     
    9999   break; 
    100100  default: 
    101     free(self); 
     101    roar_mm_free(self); 
    102102    return -1; 
    103103 } 
     
    175175 
    176176 if ( ! self->refcount ) { 
    177   free(self); 
     177  roar_mm_free(self); 
    178178 } 
    179179 
  • libroar/vio_stack.c

    r1505 r3063  
    4141  return -1; 
    4242 
    43  if ( (self = malloc(sizeof(struct roar_vio_stack))) == NULL ) 
     43 if ( (self = roar_mm_malloc(sizeof(struct roar_vio_stack))) == NULL ) 
    4444  return -1; 
    4545 
     
    9494 } 
    9595 
    96  free(self); 
     96 roar_mm_free(self); 
    9797 
    9898 return 0; 
  • 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 } 
  • libroardsp/transcode_celt.c

    r2204 r3063  
    3131 
    3232int roar_xcoder_celt_init       (struct roar_xcoder * state) { 
    33  struct roar_xcoder_celt * self = malloc(sizeof(struct roar_xcoder_celt)); 
     33 struct roar_xcoder_celt * self = roar_mm_malloc(sizeof(struct roar_xcoder_celt)); 
    3434 struct roar_audio_info  * info = &(state->info.pcm); 
    3535 
     
    3939 // curruntly only 16 bit mode is supported 
    4040 if ( info->bits != 16 ) { 
    41   free(self); 
     41  roar_mm_free(self); 
    4242  return -1; 
    4343 } 
     
    5050 
    5151 self->bufferlen            = info->channels * 32 + _SIZE_LEN; 
    52  self->iobuffer             = malloc(self->bufferlen); 
     52 self->iobuffer             = roar_mm_malloc(self->bufferlen); 
    5353 
    5454 if ( self->iobuffer == NULL ) { 
    55   free(self); 
     55  roar_mm_free(self); 
    5656  return -1; 
    5757 } 
     
    6060 
    6161 if ( self->mode == NULL ) { 
    62   free(self); 
     62  roar_mm_free(self->iobuffer); 
     63  roar_mm_free(self); 
    6364  return -1; 
    6465 } 
     
    8788 
    8889 if ( self->iobuffer ) 
    89   free(self->iobuffer); 
     90  roar_mm_free(self->iobuffer); 
    9091 
    9192 if ( self->encoder ) 
     
    9899  celt_mode_destroy(self->mode); 
    99100 
    100  free(self); 
     101 roar_mm_free(self); 
    101102 
    102103 ROAR_DBG("roar_xcoder_celt_uninit(*) = 0"); 
  • libroardsp/transcode_speex.c

    r2974 r3063  
    3333 
    3434int roar_xcoder_speex_init       (struct roar_xcoder * state) { 
    35  struct roar_xcoder_speex * self = malloc(sizeof(struct roar_xcoder_speex)); 
     35 struct roar_xcoder_speex * self = roar_mm_malloc(sizeof(struct roar_xcoder_speex)); 
    3636 struct roar_audio_info  * info = &(state->info.pcm); 
    3737 int tmp; 
     
    4444 // curruntly only 16 bit mode is supported 
    4545 if ( info->bits != 16 ) { 
    46   free(self); 
     46  roar_mm_free(self); 
    4747  return -1; 
    4848 } 
     
    5353  case 2: self->stereo = 1; break; 
    5454  default: 
    55     free(self); 
     55    roar_mm_free(self); 
    5656    return -1; 
    5757 } 
     
    140140 speex_bits_destroy(&(self->bits)); 
    141141 
    142  free(self); 
     142 roar_mm_free(self); 
    143143 
    144144 return 0; 
  • libroardsp/vio_transcode.c

    r2644 r3063  
    2727int     roar_vio_open_xcode    (struct roar_vio_calls * calls, int encoder, struct roar_audio_info * info, 
    2828                                struct roar_vio_calls * dst) { 
    29  struct roar_xcoder * xcoder = malloc(sizeof(struct roar_xcoder)); 
     29 struct roar_xcoder * xcoder = roar_mm_malloc(sizeof(struct roar_xcoder)); 
    3030 
    3131 if ( xcoder == NULL ) 
     
    3333 
    3434 if ( calls == NULL || info == NULL || dst == NULL ) { 
    35   free(xcoder); 
     35  roar_mm_free(xcoder); 
    3636  return -1; 
    3737 } 
    3838 
    3939 if ( roar_xcoder_init(xcoder, encoder, info, dst) == -1 ) { 
    40   free(xcoder); 
     40  roar_mm_free(xcoder); 
    4141  return -1; 
    4242 } 
     
    9494 
    9595 if ( vio->inst != NULL ) 
    96   free(vio->inst); 
     96  roar_mm_free(vio->inst); 
    9797 
    9898 return ret; 
     
    101101int     roar_vio_open_bixcode    (struct roar_vio_calls * calls, struct roar_audio_info * info, 
    102102                                  struct roar_vio_calls * dst) { 
    103  struct roar_bixcoder * bixcoder = malloc(sizeof(struct roar_bixcoder)); 
     103 struct roar_bixcoder * bixcoder = roar_mm_malloc(sizeof(struct roar_bixcoder)); 
    104104 
    105105 if ( bixcoder == NULL ) 
     
    107107 
    108108 if ( calls == NULL || info == NULL || dst == NULL ) { 
    109   free(bixcoder); 
     109  roar_mm_free(bixcoder); 
    110110  return -1; 
    111111 } 
    112112 
    113113 if ( roar_bixcoder_init(bixcoder, info, dst) == -1 ) { 
    114   free(bixcoder); 
     114  roar_mm_free(bixcoder); 
    115115  return -1; 
    116116 } 
     
    165165 
    166166 if ( vio->inst != NULL ) 
    167   free(vio->inst); 
     167  roar_mm_free(vio->inst); 
    168168 
    169169 return ret; 
  • roard/clients.c

    r2828 r3063  
    5151 for (i = 0; i < ROAR_CLIENTS_MAX; i++) { 
    5252  if ( g_clients[i] == NULL ) { 
    53    n = malloc(sizeof(struct roar_client)); 
     53   n = roar_mm_malloc(sizeof(struct roar_client)); 
    5454   if ( n != NULL ) { 
    5555    n->pid    = -1; 
     
    7171 
    7272    if ( roar_nnode_new(&(n->nnode), ROAR_SOCKET_TYPE_UNKNOWN) == -1 ) { 
    73      free(n); 
     73     roar_mm_free(n); 
    7474     return -1; 
    7575    } 
     
    114114 roar_nnode_free(&(g_clients[id]->nnode)); 
    115115 
    116  free(g_clients[id]); 
     116 roar_mm_free(g_clients[id]); 
    117117 g_clients[id] = NULL; 
    118118 
  • roard/streams.c

    r3042 r3063  
    6868 for (i = 0; i < ROAR_STREAMS_MAX; i++) { 
    6969  if ( g_streams[i] == NULL ) { 
    70    s = ROAR_STREAM_SERVER(n = ROAR_STREAM(malloc(sizeof(struct roar_stream_server)))); 
     70   s = ROAR_STREAM_SERVER(n = ROAR_STREAM(roar_mm_malloc(sizeof(struct roar_stream_server)))); 
    7171   if ( n == NULL ) { 
    7272    ROAR_ERR("streams_new(void): can not allocate memory for new stream: %s", strerror(errno)); 
     
    252252  free(s->name); 
    253253 
    254  free(s); 
     254 roar_mm_free(s); 
    255255 
    256256 g_streams[id] = NULL; 
Note: See TracChangeset for help on using the changeset viewer.