Skip to content

Conversation

@pilif
Copy link
Contributor

@pilif pilif commented Jun 3, 2015

the parent PDO closeCursor method resets the pdo_stmt_t's executed flag
which is used by the postgres driver as a flag to check whether to
allocate memory for the column data or not.

This means that after the parent closeCursor() has been called, the
pdo_pgsql driver will allocate a new buffer for the columns, so the
existing buffer should be freed when the cursor is being closed.

@pilif
Copy link
Contributor Author

pilif commented Jun 4, 2015

currently investigating the test failures. Please stay tuned

@pilif
Copy link
Contributor Author

pilif commented Jun 4, 2015

I have fixed the fix to deal with the failing test cases.

Please note that even without this patch, ext/pdo_pgsql/tests/pdo_014.php currently fails on my machine (due to the object IDs in var_dump() output not matching)

@laruence laruence added the Bug label Jun 5, 2015
@weltling
Copy link
Contributor

weltling commented Jun 8, 2015

@pilif what is the diff you've got for that test?

@pilif
Copy link
Contributor Author

pilif commented Jun 10, 2015

@weltling the issue was on my end, running the tests with a clean php built with just ./configure --with-pdo_pgsql, all tests pass before and after applying the patch (clean rebuilding in between just to be on the safe side)

@weltling
Copy link
Contributor

@pilif, you mean the issue you originally reported isn't reproducable anymore? Then probably no need to merge the patch.

Thanks.

@pilif
Copy link
Contributor Author

pilif commented Jun 10, 2015

@weltling no. The original issue is reproducible and the memory leak exists.

But the non-related test that was failing before doesn't fail any more.

So on my machine now:

Current PHP-5.6 HEAD:

  • all current tests pass
  • new test added by this PR fails
  • memory leak exists.

With this PR applied:

  • all existing tests pass
  • new test added by this PR passes
  • memory leak plugged.

@weltling
Copy link
Contributor

@pilif ah, so i misunderstood then. Ok, gonna test it then.

Btw did you check the same exists in 5.5 by chance?

Thanks.

@pilif
Copy link
Contributor Author

pilif commented Jun 10, 2015

@weltling - I haven't actually tested it, but the ecalloc was added in the very beginning of the PDO driver in 2004 (in 9d6c259) and the resetting of stmt->executed by closeCursor happened in 2006 with 2d4b8e1 which didn't take into account that 858d827 (added in 2005) didn't do any kind of cleanup.

So I would say everything after 2d4b8e1 leaks and everything before crashes.

@weltling
Copy link
Contributor

@pilif tested your patch - the functionality is ok. I would right apply it, but it seems to have a small charset issue. You seem to have saved some weird chars in there which look like space. Please check what i see when opening the downloaded patch with a non multibyte charset

+ if (!stmt->executed && (!stmt->column_count ||A S->cols == NULL)) {

something is definitely looks like a unicode char, Visual Studio at least fails to compile it. Please put a plain space there :)

Thanks.

@pilif
Copy link
Contributor Author

pilif commented Jun 10, 2015

oh crap. I'm terribly sorry about this. This is a non-breaking space which happens to me all the time with my swiss german keyboard as the sign is Alt-Space and to make the | sign, I have to type Alt-7. So if I leave the finger on Alt for just a small moment too long, this sneaky sucker gets added which looks just like a normal space.

I'll rebase a fixed patch and notify you again.

Terribly sorry about this - neither gcc nor clang seemed to mind :/

the parent PDO closeCursor method resets the pdo_stmt_t's executed flag
which is used by the postgres driver as a flag to check whether to
allocate memory for the column data or not.

This means that after the parent closeCursor() has been called, the
pdo_pgsql driver will allocate a new buffer for the columns, so the
existing buffer should be freed when the cursor is being closed.
@weltling
Copy link
Contributor

Fine now, gonna merge.

Thanks )

@pilif
Copy link
Contributor Author

pilif commented Jun 10, 2015

there we go. Squeaky clean without U+00a0

Sorry about wasting your time.

@php-pulls
Copy link

Comment on behalf of ab at php.net:

Merged into 5.5+. Thanks your work :)

@php-pulls php-pulls closed this Jun 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants