|
@ -30,7 +30,7 @@ |
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
|
.\" SUCH DAMAGE. |
|
|
.\" 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 |
|
|
.Dd August 27, 1996 |
|
|
.Dt MALLOC 3 |
|
|
.Dt MALLOC 3 |
|
@ -158,13 +158,14 @@ indicates that the old object still remains allocated. |
|
|
Better code looks like this: |
|
|
Better code looks like this: |
|
|
.Bd -literal -offset indent |
|
|
.Bd -literal -offset indent |
|
|
newsize = size + 50; |
|
|
newsize = size + 50; |
|
|
if ((p2 = realloc(p, newsize)) == NULL) { |
|
|
|
|
|
|
|
|
if ((newp = realloc(p, newsize)) == NULL) { |
|
|
if (p) |
|
|
if (p) |
|
|
free(p); |
|
|
free(p); |
|
|
p = NULL; |
|
|
p = NULL; |
|
|
|
|
|
size = 0; |
|
|
return (NULL); |
|
|
return (NULL); |
|
|
} |
|
|
} |
|
|
p = p2; |
|
|
|
|
|
|
|
|
p = newp; |
|
|
size = newsize; |
|
|
size = newsize; |
|
|
.Ed |
|
|
.Ed |
|
|
.Pp |
|
|
.Pp |
|
|