Boost C++ Libraries: Ticket #10506: Infinite loop in create_or_open_file https://svn.boost.org/trac10/ticket/10506 <p> This function will never exit if the call to ::open returns -1 for a reason other than EEXIST. </p> <p> inline file_handle_t create_or_open_file </p> <blockquote> <p> (const char *name, mode_t mode, const permissions &amp; perm = permissions(), bool temporary = false) </p> </blockquote> <p> { </p> <blockquote> <p> (void)temporary; int ret = -1; <em>We need a loop to change permissions correctly using fchmod, since </em>with "O_CREAT only" ::open we don't know if we've created or opened the file. while(1){ </p> <blockquote> <p> ret = ::open(name, ((int)mode) | O_EXCL | O_CREAT, perm.get_permissions()); if(ret &gt;= 0){ </p> <blockquote> <p> ::fchmod(ret, perm.get_permissions()); break; </p> </blockquote> <p> } else if(errno == EEXIST){ </p> <blockquote> <table class="wiki"> <tr>if((ret = ::open(name, (int)mode)) &gt;= 0 <td> errno != ENOENT){ </td></tr></table> <blockquote> <p> break; </p> </blockquote> <p> } </p> </blockquote> <p> } </p> </blockquote> <p> } return ret; </p> </blockquote> <p> } </p> <p> For example if the call fails due to errno == EACCESS, the function does not exit. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10506 Trac 1.4.3 Ion Gaztañaga Sat, 04 Oct 2014 09:45:45 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10506#comment:1 https://svn.boost.org/trac10/ticket/10506#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Thanks for the report. Fixed in: </p> <p> [develop 2c4f35f] Fixes Trac <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/10506" title="#10506: Bugs: Infinite loop in create_or_open_file (closed: fixed)">#10506</a> </p> <p> If error is not EEXIST, goes out of the loop </p> Ticket