Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

memory leaks #19

Open
mateeuslinno opened this issue Apr 30, 2019 · 0 comments
Open

memory leaks #19

mateeuslinno opened this issue Apr 30, 2019 · 0 comments

Comments

@mateeuslinno
Copy link

mateeuslinno commented Apr 30, 2019

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);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant