Index: branches/1.3/ChangeLog
===================================================================
--- branches/1.3/ChangeLog	(revision 706)
+++ branches/1.3/ChangeLog	(revision 708)
@@ -4,4 +4,5 @@
  * compatibility fix: fix segv on shutdown when ionCube Loader is loaded
  * fixed undefined index for xcache.count=1 and xcache.var_size>1
+ * fixed #258: builtin constant memory leak on compile
 
 1.3.1 2010-11-27
Index: branches/1.3/utils.c
===================================================================
--- branches/1.3/utils.c	(revision 706)
+++ branches/1.3/utils.c	(revision 708)
@@ -600,4 +600,12 @@
 }
 /* }}} */
+static void xc_free_zend_constant(zend_constant *c) /* {{{ */
+{
+	if (!(c->flags & CONST_PERSISTENT)) {
+		zval_dtor(&c->value);
+	}
+	free(ZSTR_V(c->name));
+}
+/* }}} */
 void xc_copy_internal_zend_constants(HashTable *target, HashTable *source) /* {{{ */
 {
@@ -643,10 +651,6 @@
 #ifdef HAVE_XCACHE_CONSTANT
 	h = OG(zend_constants);
-	zend_hash_init_ex(&TG(zend_constants),  20, NULL, h->pDestructor, h->persistent, h->bApplyProtection);
+	zend_hash_init_ex(&TG(zend_constants),  20, NULL, (dtor_func_t) xc_free_zend_constant, h->persistent, h->bApplyProtection);
 	xc_copy_internal_zend_constants(&TG(zend_constants), &XG(internal_constant_table));
-	{
-		zend_constant tmp_const;
-		zend_hash_copy(&TG(zend_constants), &XG(internal_constant_table), (copy_ctor_func_t) xc_zend_constant_ctor, (void *) &tmp_const, sizeof(tmp_const));
-	}
 	TG(internal_constant_tail) = TG(zend_constants).pListTail;
 #endif
@@ -712,4 +716,9 @@
 
 #ifdef HAVE_XCACHE_CONSTANT
+	for (b = TG(zend_constants).pListHead; b != NULL && b != TG(internal_constant_tail); b = b->pListNext) {
+		zend_constant *c = (zend_constant*) b->pData;
+		xc_free_zend_constant(c);
+	}
+
 	b = TG(internal_constant_tail) ? TG(internal_constant_tail)->pListNext : TG(zend_constants).pListHead;
 	/* install constants */
