Created
July 20, 2012 17:52
-
-
Save hdclark/3152227 to your computer and use it in GitHub Desktop.
popen Segfault
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .... | |
| FILE *fp; | |
| .... | |
| while( true ){ | |
| if(fp == nullptr) pclose(fp); // <---seg. fault happens here. (see below) | |
| // or | |
| //if(fp == 0) pclose(fp); | |
| // or | |
| //if(fp == NULL) pclose(fp); | |
| ... | |
| fp = popen(...); | |
| ... | |
| pclose(fp); | |
| //------------------------------------------------------------------------------- | |
| // NOTE: The above segfault will evaporate if you manually nullify fp. | |
| //------------------------------------------------------------------------------- | |
| fp = nullptr; // <---- This will fix the above segfault. | |
| //------------------------------------------------------------------------------- | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment