Comments (3)
The issue happens due to an attempt to free() an uninitialized pointer. More precisely: the pointer reply
is created at the top of phpiredis_command_bs()
and not initialized. It is then passed into redisGetReply()
, where it is normally replaced with a pointer to a valid redisReply object and all is good.
However, when the server goes away, this pointer is never replaced, so when freeReplyObject(reply)
is called, it is actually operating on an uninitialized pointer, which causes the segfault.
A similar problem was addressed in bccb042, but never really done properly.
Two ideas on how to avoid the segfault:
- As its impossible to check for an uninitialized pointer, the pointer could be set to NULL upon declaration. Later it could be checked for that value and only freed when it is not NULL:
if (reply) freeRedisReply(reply);
- When an error occurrs, the
err
field in the redis context is populated. Depending on the value of this field, the code could decide whether to free or not free the reply:
if (connection->c->err != REDIS_ERR_IO) freeRedisReply();
Number 1 seems cleaner, but we have tried this, and experienced some strange behavior. Maybe someone else knows how to do it properly? Number 2 seems like a hack, and may vreate a memory leak.
from phpiredis.
Ok, so initializing the pointer to NULL is really the proper way. I have opened a pull request with that fix. Please review quickly.
from phpiredis.
@theintz thanks for the detailed report and PR #21 and sorry for being so late, I'm finally starting to slowly get back to my open-source projects after a long hiatus due to the lack of free time. I just started reviewing your other (and more substantial) pull request.
from phpiredis.
Related Issues (20)
- PHP 7 support HOT 1
- Error building against PHP 5.6.8 HOT 11
- The value of phpiredis_command_bs SET must be string? HOT 4
- pls support php7 HOT 16
- Release on PECL HOT 19
- make compile error HOT 2
- PHP: Unable to load dynamic library HOT 8
- make test after make install: phpiredis extension is not available
- make test after make install: phpiredis extension is not available HOT 1
- Compatibility with PHP 7.x HOT 19
- Install ext-phpiredis On Mac El Capitan HOT 1
- [RFE] improve installation doc HOT 2
- PhpiRedis: supplied resource is not a valid phpredis reader HOT 1
- phpiredis for snc_redis HOT 2
- Failed make tests HOT 5
- Docker / Alpine installation (phpiredis.so: redisReplyReaderGetReply: symbol not found) HOT 4
- undefined symbol: redisReplyReaderGetReply in Unknown on line 0 HOT 4
- Extension fails to load when built with hiredis 0.14 on armv7h or x86_64: works on armv6h HOT 3
- Will recent Hiredis upgrades be implemented? HOT 6
- Plan to release 1.1.x HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpiredis.