[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26033] trunk/blender/source/blender/ blenkernel/intern/text.c: possible fix for [#20674] SegFault from console ' c = data.texts["text1"].copy()'

Campbell Barton ideasman42 at gmail.com
Sat Jan 16 15:06:22 CET 2010


Revision: 26033
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26033
Author:   campbellbarton
Date:     2010-01-16 15:05:39 +0100 (Sat, 16 Jan 2010)

Log Message:
-----------
possible fix for [#20674] SegFault from console 'c = data.texts["text1"].copy()'
fix for freeing the undo buffer from a copied text block. (the copy had the old undo pointer)

since I only got an error, not a segfault Im not sure this is the real cause of the crash.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/text.c

Modified: trunk/blender/source/blender/blenkernel/intern/text.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/text.c	2010-01-16 04:18:21 UTC (rev 26032)
+++ trunk/blender/source/blender/blenkernel/intern/text.c	2010-01-16 14:05:39 UTC (rev 26033)
@@ -150,6 +150,13 @@
 	return undoing;
 }
 
+static void init_undo_text(Text *text)
+{
+	text->undo_pos= -1;
+	text->undo_len= TXT_INIT_UNDO;
+	text->undo_buf= MEM_mallocN(text->undo_len, "undo buf");
+}
+
 void free_text(Text *text)
 {
 	TextLine *tmp;
@@ -179,10 +186,6 @@
 	ta->id.us= 1;
 	
 	ta->name= NULL;
-
-	ta->undo_pos= -1;
-	ta->undo_len= TXT_INIT_UNDO;
-	ta->undo_buf= MEM_mallocN(ta->undo_len, "undo buf");
 		
 	ta->nlines=1;
 	ta->flags= TXT_ISDIRTY | TXT_ISMEM;
@@ -259,9 +262,7 @@
 
 	/* clear undo buffer */
 	MEM_freeN(text->undo_buf);
-	text->undo_pos= -1;
-	text->undo_len= TXT_INIT_UNDO;
-	text->undo_buf= MEM_mallocN(text->undo_len, "undo buf");
+	init_undo_text(text);
 	
 	fseek(fp, 0L, SEEK_END);
 	len= ftell(fp);
@@ -359,9 +360,7 @@
 	ta->name= MEM_mallocN(strlen(file)+1, "text_name");
 	strcpy(ta->name, file);
 
-	ta->undo_pos= -1;
-	ta->undo_len= TXT_INIT_UNDO;
-	ta->undo_buf= MEM_mallocN(ta->undo_len, "undo buf");
+	init_undo_text(ta);
 	
 	buffer= MEM_mallocN(len, "text_buffer");
 	// under windows fread can return less then len bytes because
@@ -458,6 +457,8 @@
 	tan->curl= tan->sell= tan->lines.first;
 	tan->curc= tan->selc= 0;
 
+	init_undo_text(tan);
+
 	return tan;
 }
 
@@ -1399,9 +1400,7 @@
 		if(text->undo_len*2 > TXT_MAX_UNDO) {
 			/* XXX error("Undo limit reached, buffer cleared\n"); */
 			MEM_freeN(text->undo_buf);
-			text->undo_len= TXT_INIT_UNDO;
-			text->undo_buf= MEM_mallocN(text->undo_len, "undo buf");
-			text->undo_pos=-1;
+			init_undo_text(text);
 			return 0;
 		} else {
 			void *tmp= text->undo_buf;





More information about the Bf-blender-cvs mailing list