Michael W. Bombardieri wrote:
> Hi tech@,
> 
> Function xfree() was previously removed from rcs, so drop it from
> opencvs too...
> 
> http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/rcs/xmalloc.c?f=h#rev1.9

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.

> 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.


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