From 931675017dd28ccca8353abeff3055f0c47bc3b2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 6 Jun 2007 14:36:43 -0700 Subject: Coverity #578/579: Don't leak memory if one malloc fails but other succeeds (Unlikely to happen, since the smaller malloc was first, but still possible.) --- src/XRecord.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/XRecord.c b/src/XRecord.c index 191a504..5d2623e 100644 --- a/src/XRecord.c +++ b/src/XRecord.c @@ -462,7 +462,9 @@ XRecordGetContext(dpy, context, state_return) { client_inf = (XRecordClientInfo **) Xcalloc(count, sizeof(XRecordClientInfo*)); ret->client_info = client_inf; - client_inf_str = (XRecordClientInfo *) Xmalloc(count*sizeof(XRecordClientInfo)); + if (client_inf != NULL) { + client_inf_str = (XRecordClientInfo *) Xmalloc(count*sizeof(XRecordClientInfo)); + } if (!client_inf || !client_inf_str) { for(i = 0; i < count; i++) @@ -485,7 +487,10 @@ XRecordGetContext(dpy, context, state_return) if (xclient_inf.nRanges) { client_inf_str[i].ranges = (XRecordRange**) Xcalloc(xclient_inf.nRanges, sizeof(XRecordRange*)); - ranges = (XRecordRange*) Xmalloc(xclient_inf.nRanges * sizeof(XRecordRange)); + if (client_inf_str[i].ranges != NULL) { + ranges = (XRecordRange*) + Xmalloc(xclient_inf.nRanges * sizeof(XRecordRange)); + } if (!client_inf_str[i].ranges || !ranges) { /* XXX eat data */ UnlockDisplay(dpy); -- cgit v1.2.1