pecl-event / src / pe.c

Diff from to
 		if (!(x)) return FAILURE; \
 	} while (0);
 
-static inline void _prop_write_zval(zval **ppz, const zval *value)
+static inline void _prop_write_zval(zval **ppz, zval *value)
 {
+#if 0
 	if (!*ppz) {
 		MAKE_STD_ZVAL(*ppz);
 	}
 	/* Make a copy of the zval, avoid direct binding to the address
 	 * of value, since it breaks refcount in read_property()
 	 * causing further leaks and memory access violations */
-	REPLACE_ZVAL_VALUE(ppz, value, 1);
+	REPLACE_ZVAL_VALUE(ppz, value, PZVAL_IS_REF((zval *)value));
+#endif
+	if (!*ppz) {
+		/* if we assign referenced variable, we should separate it */
+		Z_ADDREF_P(value);
+		if (PZVAL_IS_REF(value)) {
+			SEPARATE_ZVAL(&value);
+		}
+		*ppz = value;
+	} else if (PZVAL_IS_REF(*ppz)) {
+		zval garbage = **ppz; /* old value should be destroyed */
+
+		/* To check: can't *ppz be some system variable like error_zval here? */
+		Z_TYPE_PP(ppz) = Z_TYPE_P(value);
+		(*ppz)->value = value->value;
+		if (Z_REFCOUNT_P(value) > 0) {
+			zval_copy_ctor(*ppz);
+		}
+		zval_dtor(&garbage);
+	} else {
+		zval *garbage = *ppz;
+
+		/* if we assign referenced variable, we should separate it */
+		Z_ADDREF_P(value);
+		if (PZVAL_IS_REF(value)) {
+			SEPARATE_ZVAL(&value);
+		}
+		*ppz = value;
+		zval_ptr_dtor(&garbage);
+	}
 }
 
 static inline void _prop_read_zval(zval *pz, zval **retval)
 	}
 
 	MAKE_STD_ZVAL(*retval);
-	/*REPLACE_ZVAL_VALUE(retval, pz, 1);*/
 	ZVAL_ZVAL(*retval, pz, 1, 0);
 }
 
 	php_event_t *e = (php_event_t *) obj;
 
 	if (!e->event) return NULL;
-
-	return (e->data ? &e->data : NULL);
+	if (!e->data) {
+		MAKE_STD_ZVAL(e->data);
+	}
+	return &e->data;
 }
 /* }}} */
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.