Ruslan Osmanov avatar Ruslan Osmanov committed 4064d35

Fix: EventBuffer input and output properties memory alloc errors
Add: get_property_ptr_ptr handlers for EventBuffer intput and output props

Comments (0)

Files changed (4)

classes/buffer_event.c

 	}
 
 	bev->self = zself;
+	bev->input = bev->output = NULL;
 	/* Ensure the object won't be destroyed in case if we are in a callback
 	 * XXX Get rid of this! */
 	Z_ADDREF_P(zself);

examples/httpv0client.php

 
 /* Read callback */
 function readcb($bev, $base) {
-	$input = $bev->input; //$bev->getInput();
+	//$input = $bev->input; //$bev->getInput();
+	
+	//$pos = $input->search("TTP");
+	$pos = $bev->input->search("TTP");
 
-	$pos = $input->search("TTP");
-
-	while (($n = $input->remove($buf, 1024)) > 0) {
+	while (($n = $bev->input->remove($buf, 1024)) > 0) {
 		echo $buf;
 	}
 }
 			b->self = NULL;
 		}
 #endif
+		if (b->input) {
+			zval_ptr_dtor(&b->input);
+			b->input = NULL;
+		}
+
+		if (b->output) {
+			zval_ptr_dtor(&b->output);
+			b->output= NULL;
+		}
 
 		if (b->bevent) {
 			bufferevent_free(b->bevent);
 {
 	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
 
+	MAKE_STD_ZVAL(*retval);
+
 	if (bev->input) {
-		*retval = bev->input;
-		Z_ADDREF_P(bev->input);
+		ZVAL_ZVAL(*retval, bev->input, 1, 0);
 		return SUCCESS;
 	}
 
 	php_event_buffer_t *b;
 
-	MAKE_STD_ZVAL(*retval);
-
 	PHP_EVENT_INIT_CLASS_OBJECT(*retval, php_event_buffer_ce);
 	PHP_EVENT_FETCH_BUFFER(b, *retval);
 
 	b->buf      = bufferevent_get_input(bev->bevent);
 	b->internal = 1;
 
-	// Cache the pointer
-	bev->input = *retval;
+	MAKE_STD_ZVAL(bev->input);
+	ZVAL_ZVAL(bev->input, *retval, 1, 0);
 	Z_ADDREF_P(bev->input);
 
 	return SUCCESS;
 {
 	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
 
+	MAKE_STD_ZVAL(*retval);
 	if (bev->output) {
-		*retval = bev->output;
+		ZVAL_ZVAL(*retval, bev->output, 1, 0);
 		Z_ADDREF_P(bev->output);
 		return SUCCESS;
 	}
 
 	php_event_buffer_t *b;
 
-	MAKE_STD_ZVAL(*retval);
-
 	PHP_EVENT_INIT_CLASS_OBJECT(*retval, php_event_buffer_ce);
 	PHP_EVENT_FETCH_BUFFER(b, *retval);
 
 	b->buf      = bufferevent_get_output(bev->bevent);
 	b->internal = 1;
 
-	// Cache the pointer
-	bev->output = *retval;
+	MAKE_STD_ZVAL(bev->output);
+	ZVAL_ZVAL(bev->output, *retval, 1, 0);
 	Z_ADDREF_P(bev->output);
 
 	return SUCCESS;
 /* }}} */
 
 
+/* {{{ event_bevent_input_prop_ptr_ptr */
+static zval **event_bevent_input_prop_ptr_ptr(php_event_abstract_object_t *obj TSRMLS_DC)
+{
+	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
+
+	return bev->input ? &bev->input : NULL;
+}
+/* }}} */
+
+/* {{{ event_bevent_output_prop_ptr_ptr */
+static zval **event_bevent_output_prop_ptr_ptr(php_event_abstract_object_t *obj TSRMLS_DC)
+{
+	php_event_bevent_t *bev = (php_event_bevent_t *) obj;
+
+	return bev->output ? &bev->output : NULL;
+}
+/* }}} */
+
+
 #if LIBEVENT_VERSION_NUMBER >= 0x02010100
 /* {{{ event_bevent_allow_ssl_dirty_shutdown_prop_write*/
 static int event_bevent_allow_ssl_dirty_shutdown_prop_write(php_event_abstract_object_t *obj, zval *value TSRMLS_DC)
 };
 const php_event_property_entry_t event_bevent_property_entries[] = {
 	{"priority", sizeof("priority") - 1, event_bevent_priority_prop_read, event_bevent_priority_prop_write, NULL },
-	{"input",    sizeof("input")    - 1, event_bevent_input_prop_read,    NULL,                             NULL },
-	{"output",   sizeof("output")   - 1, event_bevent_output_prop_read,   NULL,                             NULL },
+	{"input",    sizeof("input")    - 1, event_bevent_input_prop_read,    NULL,                             event_bevent_input_prop_ptr_ptr},
+	{"output",   sizeof("output")   - 1, event_bevent_output_prop_read,   NULL,                             event_bevent_output_prop_ptr_ptr},
 
 #if LIBEVENT_VERSION_NUMBER >= 0x02010100
 	{"allow_ssl_dirty_shutdown", sizeof("allow_ssl_dirty_shutdown") - 1,
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.