Skip to content
Snippets Groups Projects

Fix memory leaks in parameter API

Closed Derek Buitenhuis requested to merge dwbuiten/x264:api_leak_fix into master
  1. Apr 15, 2020
    • Derek Buitenhuis's avatar
      API: Properly handle allocation failures in x264_param_parse() · 0a6827b5
      Derek Buitenhuis authored
      
      Check to make sure no call to strdup() failed to allocate.
      
      A new return code, X264_PARAM_ALLOC_FAILED, which is consistent
      with the existing documentation, has been added to accomodate
      this.
      
      Further, this also properly handles repeated calls to the
      function with the same name, and no longer leaks when this
      happens.
      
      Signed-off-by: default avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
      0a6827b5
    • Derek Buitenhuis's avatar
      API: Add x264_param_cleanup() · d0f25403
      Derek Buitenhuis authored
      
      Currently, x264_param_parse() calls strdup() to populate any member of
      x264_param_t that is a string, and this leaks on exit. This is a small
      amount on its own, but can compound over time, if, for example, a long
      running application creates and destroys many encoders over its lifetime.
      
      To fix this, we add a new API call that frees these members, but not
      the x264_param_t itself, which may exist on the stack. The reason we
      need an API call, instead of just having the user free these fields,
      is because we allocate these fields inside libx264, and our strdup()
      may mismtach with the user's free().
      
      One change that must be made to accomodate this new API, is that
      x264_param_default() must allocate the default stats filename on
      the heap, instead of the stack, since we try to free it later.
      This is a little awkward, since x264_param_default() is a void
      type.
      
      Signed-off-by: default avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
      d0f25403
Loading