echoprint-server icon indicating copy to clipboard operation
echoprint-server copied to clipboard

memory leaks

Open mateeuslinno opened this issue 6 years ago • 0 comments

Hi, i found some possible memory leak.

src: echoprint-server/libechoprintserver.c

Line 318:  out = (uint32_t *) malloc(sizeof(uint32_t) * out_len);
  i = 0;
  for(n = 0; n < n_sequences; n++)
  {
    uint32_t len_n = sequence_lengths[n];
    memcpy(out + i, sequences[n], sizeof(uint32_t) * len_n);
    i += len_n;
  }
  _sequence_to_set_inplace(out, &out_len);
  *output_length = out_len;
  *output = out;
}

==============================

**Line 345** **code_lengths** = (uint32_t *) malloc(sizeof(uint32_t) * n_codes);
  for(i = 0; i < n_codes; i++)
    code_lengths[i] = 0;
  for(i = 0; i < n_songs; i++)
  {
    int offset = 0;
    for(c = 0; c < song_lengths[i]; c++)
    {
      while(codes[offset] != songs_codes[i][c])
        offset++;
      code_lengths[offset]++;
    }
  }

  code_lengths_sum = 0;
  for(c = 0; c < n_codes; c++)
    code_lengths_sum += code_lengths[c];
  song_indices = (uint16_t *) malloc(
    sizeof(uint16_t) * code_lengths_sum);

  code_offsets = (uint32_t *) malloc(sizeof(uint32_t) * n_codes);
  code_offsets[0] = 0;
  for(c = 1; c < n_codes; c++)
    code_offsets[c] = code_offsets[c-1] + code_lengths[c-1];
  for(i = 0; i < n_songs; i++)
  {
    int offset = 0;
    for(c = 0; c < song_lengths[i]; c++)
    {
      uint32_t code = songs_codes[i][c];
      while(codes[offset] != code)
        offset++;
      song_indices[code_offsets[offset]] = i;
      code_offsets[offset]++;
    }
  }
  free(code_offsets);

mateeuslinno avatar Apr 30 '19 01:04 mateeuslinno