Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BUG #1214 #1215

Closed
wants to merge 12 commits into from
Closed

Fix BUG #1214 #1215

wants to merge 12 commits into from

Conversation

dreamsxin
Copy link
Contributor

Fix BUG #1214
Fix some BUG
Perfect unit-tests/ImageTest.php

@ghost
Copy link

ghost commented Sep 10, 2013

diff --git a/ext/image/adapter.c b/ext/image/adapter.c
index ec1267f..11e1611 100644
--- a/ext/image/adapter.c
+++ b/ext/image/adapter.c
@@ -266,10 +266,10 @@ PHP_METHOD(Phalcon_Image_Adapter, resize){
                        tmp_height = 1;
                }

-               PHALCON_INIT_NVAR(width);
+               zval_dtor(width);
                ZVAL_LONG(width, tmp_width);

-               PHALCON_INIT_NVAR(height);
+               zval_dtor(height);
                ZVAL_LONG(height, tmp_height);
        }

In brief: it is unsafe to call PHALCON_INIT_NVAR() or PHALCON_OBS_NVAR() on parameters passed to the function.

  1. All arguments are passed as zval** — that is, Zend Engine remembers the location of every arguments.
  2. If argument's reference count is 1, PHALCON_SEPARATE_PARAM() macro does nothing — arguments are separated only whne their reference count is greater than 1.
  3. PHALCON_INIT_NVAR() destroys zval* by caling zval_ptr_dtor(). Since reference count is 1, this destroys the argument and frees the memory allocated for it.
  4. After that PHALCON_INIT_NVAR() calls ALLOC_INIT_ZVAL() to allocate the memory for that zval again.

The issue is that ALLOC_INIT_ZVAL() could allocate a zval at a different memory region and as a consequence, zval** that Zend Engine has will point to the old (destroyed) zval*, not to the newly allocated one.

@dreamsxin
Copy link
Contributor Author

Thank you, I get rid of the other places

@dreamsxin dreamsxin closed this Sep 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant