Bug #63595 [Opn]: GMP memory management conflicts with other libraries using GMP

From: Date: Sat, 18 Oct 2014 08:06:39 +0000
Subject: Bug #63595 [Opn]: GMP memory management conflicts with other libraries using GMP
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188178@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63595&edit=1

 ID:                 63595
 Updated by:         stas@php.net
 Reported by:        arekm at maven dot pl
 Summary:            GMP memory management conflicts with other libraries
                     using GMP
 Status:             Open
 Type:               Bug
 Package:            GNU MP related
 PHP Version:        5.3.19
 Block user comment: N
 Private report:     N

 New Comment:

The big problem is that nobody guarantees us gnutls GMP object lifetimes would match PHP request
lifetime. They could allocate something outside the request and free inside, or vice versa.


Previous Comments:
------------------------------------------------------------------------
[2014-10-14 07:30:38] remi@php.net

Problem with having the PHP allocator set globally during all the request, is that it will be used
by other libraries (ex freetds or zarafa/mapi), and then the free (during exit / 
gnutls_global_deinit) will segfault:
- using php efree as the php memory allocator is already shutdown
- using standard free as the php was not allocated using malloc

------------------------------------------------------------------------
[2014-10-11 09:51:51] nikic@php.net

Before going with ugly solutions like switching the allocator in every single function, could we
please try the approach of

a) resetting memory allocators in MSHUTDOWN
b) setting memory allocators in RINIT and resetting in RSHUTDOWN.

I'd much prefer this to happen on every request regardless of GMP usage than for every single
GMP function call.

------------------------------------------------------------------------
[2014-10-11 06:50:32] remi@php.net

The following patch has been added/updated:

Patch Name: gmp-memory.patch
Revision:   1413010232
URL:        https://bugs.php.net/patch-display.php?bug=63595&patch=gmp-memory.patch&revision=1413010232

------------------------------------------------------------------------
[2014-10-11 06:16:36] remi@php.net

The following patch has been added/updated:

Patch Name: gmp-memory.patch
Revision:   1413008196
URL:        https://bugs.php.net/patch-display.php?bug=63595&patch=gmp-memory.patch&revision=1413008196

------------------------------------------------------------------------
[2014-10-10 23:43:24] rasmus@php.net

ext/gmp calls mp_set_memory_functions() in the MINIT hook so it should be fine for any PHP
extensions that might use it. I don't see how a curl ssl call from PHP would end up having a
problem. However, I can see the cases Remi mentioned where non-php things like mod_gnutls gets in
the mix. Might have to set it back in RSHUTDOWN, but I would hate having to do that. Anything in the
per-request hooks end up getting called on every request regardless of whether anything used
anything from gmp on that request.

The other option would be to yank it from MINIT and do it for every gmp operation/object.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=63595


--
Edit this bug report at https://bugs.php.net/bug.php?id=63595&edit=1


Thread (10 messages)

« previous php.bugs (#188178) next »