=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/sshbuf.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- src/usr.bin/ssh/sshbuf.c 2018/07/09 21:56:06 1.12 +++ src/usr.bin/ssh/sshbuf.c 2018/11/16 06:10:29 1.13 @@ -1,4 +1,4 @@ -/* $OpenBSD: sshbuf.c,v 1.12 2018/07/09 21:56:06 markus Exp $ */ +/* $OpenBSD: sshbuf.c,v 1.13 2018/11/16 06:10:29 djm Exp $ */ /* * Copyright (c) 2011 Damien Miller * @@ -141,13 +141,8 @@ */ if (sshbuf_check_sanity(buf) != 0) return; + /* - * If we are a child, the free our parent to decrement its reference - * count and possibly free it. - */ - sshbuf_free(buf->parent); - buf->parent = NULL; - /* * If we are a parent with still-extant children, then don't free just * yet. The last child's call to sshbuf_free should decrement our * refcount to 0 and trigger the actual free. @@ -155,6 +150,14 @@ buf->refcount--; if (buf->refcount > 0) return; + + /* + * If we are a child, the free our parent to decrement its reference + * count and possibly free it. + */ + sshbuf_free(buf->parent); + buf->parent = NULL; + if (!buf->readonly) { explicit_bzero(buf->d, buf->alloc); free(buf->d);