> Good catch, thanks.
> 
> My eyes glazed over a little while reviewing this, but tentative ok
> mmcc@
> 
> Below is what I consider a better refactoring of buf_free(). It makes it
> NULL-safe and has more classic free function logic.

I didn't include buf_free() in my patch but that looks good.

> > Footnote:
> > I noticed that rcsnum_free() is just free() so maybe that could be
> > removed also (not included in this patch).
> 
> I'll have to look, but this sounds like a good idea to me.

In rcs(1) rcsnum_free() is more complicated since rn_id is dynamically 
allocated.

> Index: buf.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/cvs/buf.c,v
> retrieving revision 1.82
> diff -u -p -r1.82 buf.c
> --- buf.c     5 Feb 2015 12:59:57 -0000       1.82
> +++ buf.c     5 Nov 2015 05:08:57 -0000
> @@ -119,15 +119,15 @@ buf_load_fd(int fd)
>  void
>  buf_free(BUF *b)
>  {
> -     if (b->cb_buf != NULL)
> -             xfree(b->cb_buf);
> -     xfree(b);
> +     if (b != NULL) {
> +             free(b->cb_buf);
> +             free(b);
> +     }
>  }
>  
>  /*
>   * Free the buffer <b>'s structural information but do not free the contents
> - * of the buffer.  Instead, they are returned and should be freed later using
> - * xfree().
> + * of the buffer.  Instead, they are returned and should be freed later.
>   */
>  void *
>  buf_release(BUF *b)
> @@ -135,7 +135,7 @@ buf_release(BUF *b)
>       void *tmp;
>  
>       tmp = b->cb_buf;
> -     xfree(b);
> +     free(b);
>       return (tmp);
>  }
>  

Reply via email to