chg: use mallocx and reallocx in hgclient
authorJun Wu <quark@fb.com>
Wed, 17 Feb 2016 15:08:09 +0000
changeset 28166 c6e0c2533e5f
parent 28165 c6705c6303dd
child 28167 66f6dad20c19
chg: use mallocx and reallocx in hgclient This patch simplifies the code a bit, and reduces the binary size a little.
contrib/chg/hgclient.c
--- a/contrib/chg/hgclient.c	Wed Feb 17 14:51:38 2016 +0000
+++ b/contrib/chg/hgclient.c	Wed Feb 17 15:08:09 2016 +0000
@@ -84,10 +84,7 @@
 
 	newsize = defaultdatasize
 		* ((newsize + defaultdatasize - 1) / defaultdatasize);
-	char *p = realloc(ctx->data, newsize);
-	if (!p)
-		abortmsg("failed to allocate buffer");
-	ctx->data = p;
+	ctx->data = reallocx(ctx->data, newsize);
 	ctx->maxdatasize = newsize;
 	debugmsg("enlarge context buffer to %zu", ctx->maxdatasize);
 }
@@ -195,9 +192,7 @@
 	for (;;) {
 		if (nargs + 1 >= maxnargs) {  /* including last NULL */
 			maxnargs += 256;
-			args = realloc(args, maxnargs * sizeof(args[0]));
-			if (!args)
-				abortmsg("failed to allocate args buffer");
+			args = reallocx(args, maxnargs * sizeof(args[0]));
 		}
 		args[nargs] = s;
 		nargs++;
@@ -432,9 +427,7 @@
 			 addr.sun_path, errno);
 	}
 
-	hgclient_t *hgc = malloc(sizeof(hgclient_t));
-	if (!hgc)
-		abortmsg("failed to allocate hgclient object");
+	hgclient_t *hgc = mallocx(sizeof(hgclient_t));
 	memset(hgc, 0, sizeof(*hgc));
 	hgc->sockfd = fd;
 	initcontext(&hgc->ctx);