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