Module Name:    xsrc
Committed By:   christos
Date:           Fri Oct  7 16:05:13 UTC 2016

Modified Files:
        xsrc/external/mit/libXtst/dist/src: XRecord.c

Log Message:
CID 1373522: Fix memory leak


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 xsrc/external/mit/libXtst/dist/src/XRecord.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/libXtst/dist/src/XRecord.c
diff -u xsrc/external/mit/libXtst/dist/src/XRecord.c:1.5 xsrc/external/mit/libXtst/dist/src/XRecord.c:1.6
--- xsrc/external/mit/libXtst/dist/src/XRecord.c:1.5	Tue Oct  4 18:01:49 2016
+++ xsrc/external/mit/libXtst/dist/src/XRecord.c	Fri Oct  7 12:05:13 2016
@@ -757,15 +757,15 @@ parse_reply_call_callback(
 		current_index += 4;
 	    }
 	    if (current_index + 1 > rep->length << 2)
-		return Error;
+		goto out;
 	    switch (reply->buf[current_index]) {
 	    case X_Reply: /* reply */
 		if (current_index + 8 > rep->length << 2)
-		    return Error;
+		    goto out;
 		EXTRACT_CARD32(rep->clientSwapped,
 			       reply->buf+current_index+4, datum_bytes);
 		if (datum_bytes < 0 || datum_bytes > ((INT_MAX >> 2) - 8))
-		    return Error;
+		    goto out;
 		datum_bytes = (datum_bytes+8) << 2;
 		break;
 	    default: /* error or event */
@@ -775,7 +775,7 @@ parse_reply_call_callback(
 	case XRecordFromClient:
 	    if (rep->elementHeader&XRecordFromClientTime) {
 		if (current_index + 4 > rep->length << 2)
-		    return Error;
+		    goto out;
 		EXTRACT_CARD32(rep->clientSwapped,
 			       reply->buf+current_index,
 			       data->server_time);
@@ -783,19 +783,19 @@ parse_reply_call_callback(
 	    }
 	    if (rep->elementHeader&XRecordFromClientSequence) {
 		if (current_index + 4 > rep->length << 2)
-		    return Error;
+		    goto out;
 		EXTRACT_CARD32(rep->clientSwapped,
 			       reply->buf+current_index,
 			       data->client_seq);
 		current_index += 4;
 	    }
 	    if (current_index + 4 > rep->length<<2)
-		return Error;
+		goto out;
 	    if (reply->buf[current_index+2] == 0
 		&& reply->buf[current_index+3] == 0) /* needn't swap 0 */
 	    {	/* BIG-REQUESTS */
 		if (current_index + 8 > rep->length << 2)
-		    return Error;
+		    goto out;
 		EXTRACT_CARD32(rep->clientSwapped,
 			       reply->buf+current_index+4, datum_bytes);
 	    } else {
@@ -803,12 +803,12 @@ parse_reply_call_callback(
 			       reply->buf+current_index+2, datum_bytes);
 	    }
 	    if (datum_bytes < 0 || datum_bytes > INT_MAX >> 2)
-		return Error;
+		goto out;
 	    datum_bytes <<= 2;
 	    break;
 	case XRecordClientStarted:
 	    if (current_index + 8 > rep->length << 2)
-		return Error;
+		goto out;
 	    EXTRACT_CARD16(rep->clientSwapped,
 			   reply->buf+current_index+6, datum_bytes);
 	    datum_bytes = (datum_bytes+2) << 2;
@@ -816,19 +816,19 @@ parse_reply_call_callback(
 	case XRecordClientDied:
 	    if (rep->elementHeader&XRecordFromClientSequence) {
 		if (current_index + 4 > rep->length << 2)
-		    return Error;
+		    goto out;
 		EXTRACT_CARD32(rep->clientSwapped,
 			       reply->buf+current_index,
 			       data->client_seq);
 		current_index += 4;
 	    } else if (current_index < rep->length << 2)
-		return Error;
+		goto out;
 	    datum_bytes = 0;
 	    break;
 	case XRecordStartOfData:
 	case XRecordEndOfData:
 	    if (current_index < rep->length << 2)
-		return Error;
+		goto out;
 	    datum_bytes = 0;
 	    break;
 	}
@@ -839,7 +839,7 @@ parse_reply_call_callback(
 			"XRecord: %lu-byte reply claims %d-byte element (seq %lu)\n",
 			(unsigned long)rep->length << 2, current_index + datum_bytes,
 			dpy->last_request_read);
-		return Error;
+		goto out;
 	    }
 	    /*
 	     * This assignment (and indeed the whole buffer sharing
@@ -862,6 +862,9 @@ parse_reply_call_callback(
 	return End;
 
     return Continue;
+out:
+    Xfree(data);
+    return Error;
 }
 
 Status

Reply via email to