Skip to content

Commit 7a5faf7

Browse files
committed
cleanup c++filt
1 parent 642df45 commit 7a5faf7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/app/main.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static void dumpBacktrace( unsigned int depth )
211211
depth = 20;
212212

213213
#if (defined(linux) && !defined(ANDROID)) || defined(__FreeBSD__)
214+
int stderr_fd = -1;
214215
if ( access( "/usr/bin/c++filt", X_OK ) < 0 )
215216
{
216217
myPrint( "Stacktrace (c++filt NOT FOUND):\n" );
@@ -230,15 +231,25 @@ static void dumpBacktrace( unsigned int depth )
230231
}
231232

232233
myPrint( "Stacktrace (piped through c++filt):\n" );
234+
stderr_fd = dup( STDERR_FILENO );
233235
close( fd[0] ); // close reading end
234236
close( STDERR_FILENO ); // close stderr
235237
dup( fd[1] ); // stderr to pipe
238+
close( fd[1] ); // close duped pipe
236239
}
237240

238241
void **buffer = new void *[ depth ];
239242
int nptrs = backtrace( buffer, depth );
240243
backtrace_symbols_fd( buffer, nptrs, STDERR_FILENO );
241244
delete [] buffer;
245+
if ( stderr_fd >= 0 )
246+
{
247+
int status;
248+
close( STDERR_FILENO );
249+
dup( stderr_fd );
250+
close( stderr_fd );
251+
wait( &status );
252+
}
242253
#elif defined(Q_OS_WIN)
243254
void **buffer = new void *[ depth ];
244255

0 commit comments

Comments
 (0)