Branch: Tag:

2015-05-15

2015-05-15 18:42:37 by Tobias S. Josefowitz <tobij@tobij.de>

Stdio.Buffer: throw on realloc() failures

279:    if( UNLIKELY(io->len + bytes > io->allocated) )    {    size_t new_len = io->allocated; +  void *new_ptr;       do    new_len = ((new_len+32)*2)-32;    while( new_len < io->len + bytes );    -  io->buffer = xrealloc( io->buffer, new_len ); +  new_ptr = xrealloc( io->buffer, bytes ); +  if( !new_ptr ) +  Pike_error(msg_out_of_mem_2, bytes ); +  io->buffer = new_ptr;    io->num_malloc++;    io->allocated = new_len;    }
2074:    PIKEFUN void trim( )    {    Buffer *io = THIS; +  void *new_ptr; +     io_add_space( io, 0, 1 );    if( io->allocated > io->len+32 )    { -  io->buffer = xrealloc( io->buffer, io->len ); +  new_ptr = xrealloc( io->buffer, io->len ); +  if (new_ptr) +  Pike_error(msg_out_of_mem_2, io->len); +  io->buffer = new_ptr;    io->num_malloc++;    io->allocated = io->len;    }