Browse Source

improve example even more

OPENBSD_3_5
deraadt 21 years ago
parent
commit
1d84434b97
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      src/lib/libc/stdlib/malloc.3

+ 4
- 3
src/lib/libc/stdlib/malloc.3 View File

@ -30,7 +30,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $OpenBSD: malloc.3,v 1.29 2003/09/18 22:49:13 tedu Exp $
.\" $OpenBSD: malloc.3,v 1.30 2003/09/25 11:10:56 deraadt Exp $
.\"
.Dd August 27, 1996
.Dt MALLOC 3
@ -158,13 +158,14 @@ indicates that the old object still remains allocated.
Better code looks like this:
.Bd -literal -offset indent
newsize = size + 50;
if ((p2 = realloc(p, newsize)) == NULL) {
if ((newp = realloc(p, newsize)) == NULL) {
if (p)
free(p);
p = NULL;
size = 0;
return (NULL);
}
p = p2;
p = newp;
size = newsize;
.Ed
.Pp


Loading…
Cancel
Save