Skip to content
Snippets Groups Projects
  • Richard Mudgett's avatar
    ee08f10d
    Fix ast_(v)asprintf() malloc failure usage conditions. · ee08f10d
    Richard Mudgett authored
    When (v)asprintf() fails, the state of the allocated buffer is undefined.
    The library had better not leave an allocated buffer as a result or no one
    will know to free it.  The most likely way it can return failure is for an
    allocation failure.  If the printf conversion fails then you actually have
    a threading problem which is much worse because another thread modified
    the parameter values.
    
    * Made __ast_asprintf()/__ast_vasprintf() set the returned buffer to NULL
    on failure.  That is much more useful than either an uninitialized pointer
    or a pointer that has already been freed.  Many uses won't have to check
    for failure to ensure that the buffer won't be double freed or prevent an
    attempt to free an uninitialized pointer.
    
    * stasis.c: Fixed memory leak in multi_object_blob_to_ami() allocated by
    ast_asprintf().
    
    * ari/resource_bridges.c:ari_bridges_play_helper(): Remove assignment to
    the wrong thing which is now not needed even if assigning to the right
    thing.
    
    Change-Id: Ib5252fb8850ecf0f78ed0ee2ca0796bda7e91c23
    ee08f10d
    History
    Fix ast_(v)asprintf() malloc failure usage conditions.
    Richard Mudgett authored
    When (v)asprintf() fails, the state of the allocated buffer is undefined.
    The library had better not leave an allocated buffer as a result or no one
    will know to free it.  The most likely way it can return failure is for an
    allocation failure.  If the printf conversion fails then you actually have
    a threading problem which is much worse because another thread modified
    the parameter values.
    
    * Made __ast_asprintf()/__ast_vasprintf() set the returned buffer to NULL
    on failure.  That is much more useful than either an uninitialized pointer
    or a pointer that has already been freed.  Many uses won't have to check
    for failure to ensure that the buffer won't be double freed or prevent an
    attempt to free an uninitialized pointer.
    
    * stasis.c: Fixed memory leak in multi_object_blob_to_ami() allocated by
    ast_asprintf().
    
    * ari/resource_bridges.c:ari_bridges_play_helper(): Remove assignment to
    the wrong thing which is now not needed even if assigning to the right
    thing.
    
    Change-Id: Ib5252fb8850ecf0f78ed0ee2ca0796bda7e91c23
db.c 27.63 KiB