View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000453 | Xdebug | Uncategorized | public | 2009-07-17 12:21 | 2009-09-06 23:05 |
Reporter | trekker | Assigned To | |||
Priority | normal | Severity | major | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Product Version | 2.0.0dev | ||||
Summary | 0000453: Memory Leaks | ||||
Description | I wonder why nobody ever reported XDebug memory leaks. These leaks have been inside of XDebug for years. Every time I upgrade I have to make a major leak cleanup. Never use memory allocation MACROS inside MACRO! Take a look on the following simple script. It will cause leaks, and so does XDebug... #define xdstrdup strdup void print_text_and_free_ex(char *text, int length) #define print_text_and_free(t) \ void LeakTest() | ||||
Additional Information | Detected memory leaks! | ||||
Tags | No tags attached. | ||||
Operating System | |||||
PHP Version | 5.3.0 | ||||
|
That bit of C code should not leak, if it does, the memory allocation algorithms are quite broken on your system. As for Xdebug specifically, please provide a short reproducible script to show that Xdebug leaks. |
|
The leaks have been inside when using VC6, VC8, VC9 compilers. Have you ever used any kind of leak detectors ? If not, I suggest to use one... As I already mentioned the culprit is using macros inside macro. See my first description where I use C code to produce leak. This is the same memory allocation code you use in XDebug. In function LeakTest() every line of code causes memory to be allocated twice! 1) compiler resolves MACRO, 2) compiler resolves MACRO inside MACRO |
|
Macros are resolved by the compiler and have nothing to do with runtime code. During runtime, the memory is only allocated once. Yes, I have used leak detectors (on Linux) and it's fine (at least for this general case). That bit of C code should not leak, if it does, the memory allocation algorithms are quite broken on your system. As for Xdebug specifically, please provide a short reproducible script to show that Xdebug leaks. |
|
Here you go. Below is a Windows example which uses debug runtime macros to report memory leaks. It will produce 2 leaks, both 13 bytes long. #include <windows.h> #define xdstrdup strdup void print_text_and_free_ex(char *text, int length); #define print_text_and_free(t) \ void print_text_and_free_ex(char *text, int length) void LeakTest() int main(int argc, char* argv[])
#endif / #ifdef _DEBUG/
} |
|
Duh, it took me some time to realize that due that the macro expanded to: print_text_and_free_ex( (xdstrdup("TEST1")), strlen(xdstrdup("TEST1")) ) That has little to do with macros inside a macro though. Anyway, it's fixed in CVS now. There are two tiny (2x 2 bytes) leaks left, but they only happen when starting/shutting down and are not repeatable. |
Date Modified | Username | Field | Change |
---|---|---|---|
2009-07-17 12:21 | trekker | New Issue | |
2009-07-17 12:21 | trekker | PHP Version | => 5.3.0 |
2009-07-17 12:21 | trekker | Xdebug Version | => 2.0.5 |
2009-08-01 17:38 | derick | Note Added: 0001018 | |
2009-08-01 17:38 | derick | Status | new => feedback |
2009-08-17 06:44 | trekker | Note Added: 0001041 | |
2009-08-22 13:26 | derick | Note Added: 0001049 | |
2009-08-27 11:46 | trekker | Note Added: 0001058 | |
2009-09-06 23:05 | derick | Note Added: 0001065 | |
2009-09-06 23:05 | derick | Status | feedback => closed |
2009-09-06 23:05 | derick | Resolution | open => fixed |
2016-07-31 12:36 | derick | Category | Usage problems => Usage problems (Crashes) |
2016-07-31 12:38 | derick | Category | Usage problems (Crashes) => Usage problems (Wrong Results) |
2020-03-12 16:35 | derick | Category | Usage problems (Wrong Results) => Variable Display |
2020-03-12 16:38 | derick | Category | Variable Display => Uncategorized |