Free the fulltext of unmatched revisions while searching for the
requested revision to avoid exhausting all available memory during
the search.  It might be better to track the revision that contains
the current fulltext (curtextrev) and dropping curtext.

--- rcsparse.c.orig	Fri Aug  7 00:21:50 2009
+++ rcsparse.c	Mon Nov 14 05:44:05 2011
@@ -937,7 +937,7 @@ rcscheckout(struct rcsfile *rcs, const char *revstr, s
 {
 	struct rcsrev searchrev;
 	struct rcstoken searchtok;
-	struct rcsrev *currcsrev;
+	struct rcsrev *currcsrev, *curtextrev;
 	struct stringinfo *curtext;
 	struct rcstoken *nextrev;
 	char *branchrev, *tmpstr;
@@ -946,6 +946,7 @@ rcscheckout(struct rcsfile *rcs, const char *revstr, s
 	if (rcsparsetree(rcs) < 0)
 		return NULL;
 
+	curtextrev = NULL;
 	curtext = NULL;
 	nextrev = NULL;
 	branchrev = NULL;
@@ -986,6 +987,7 @@ rcscheckout(struct rcsfile *rcs, const char *revstr, s
 
 		if (curtext == NULL) {
 			curtext = currcsrev->rawtext;
+			curtextrev = currcsrev;
 		} else {
 			if (nextrev == NULL)
 				goto fail;
@@ -995,7 +997,12 @@ rcscheckout(struct rcsfile *rcs, const char *revstr, s
 
 			if (currcsrev->text) {
 				/* Was expanded before */
+				if (curtextrev != NULL) {
+					free(curtextrev->text);
+					curtextrev->text = NULL;
+				}
 				curtext = currcsrev->text;
+				curtextrev = currcsrev;
 			} else {
 				if (currcsrev->rawtext == NULL)
 					goto fail;
@@ -1004,9 +1011,12 @@ rcscheckout(struct rcsfile *rcs, const char *revstr, s
 					goto fail;
 				if (applydelta(&currcsrev->text, currcsrev->rawtext) < 0)
 					goto fail;
-				free(currcsrev->rawtext);
-				currcsrev->rawtext = NULL;
+				if (curtextrev != NULL) {
+					free(curtextrev->text);
+					curtextrev->text = NULL;
+				}
 				curtext = currcsrev->text;
+				curtextrev = currcsrev;
 			}
 		}
 
