[RFA] Fix memory leak in gdbserver/hostio.c

Pedro Alves pedro@codesourcery.com
Sun Feb 27 17:10:00 GMT 2011


On Sunday 27 February 2011 00:30:38, Michael Snyder wrote:
> Found by coverity.

Do you try running coverity on your patches?

> @@ -367,6 +367,7 @@ handle_pwrite (char *own_buf, int packet
>        || require_data (p, packet_len - (p - own_buf), &data, &len))
>      {
>        hostio_packet_error (own_buf);
> +      free (data);
>        return;
>      }

This is wrong.  If any predicate other than require_data in if above
returned true, then you'll be freeing a garbage pointer.  I'd
fix this in require_data ... just free the output buffer when
returning error, so the callers never have to.

-- 
Pedro Alves



More information about the Gdb-patches mailing list