CleverRaven/Cataclysm-DDA — pull request #3581 by phaethonfire (2013-10-12 03:01:28+00:00)
Title: Fix segfault in file_finder.cpp

At rutime, I was getting a segfault. A backtrace showed this:

(gdb) backtrace
#0 0x00007fff8a736162 in closedir ()
#1 0x00000001001a8b5a in file_finder::get_files_from_path (extension=@0x7fff5fbfa4f8, root_path=@0x7fff5fbfa4f0, recursive_search=true) at file_finder.cpp:73
#2 0x000000010084182c in get_tileset_names (dir_path=@0x7fff5fbfb738) at options.cpp:851
#3 0x00000001008447ef in initOptions () at options.cpp:315
#4 0x00000001004b38cb in main (argc=0, argv=0x7fff5fbff978) at main.cpp:66

stepping through showed this:

68 subdir = opendir(subpath.c_str());
(gdb)
69 if (subdir)
(gdb)
73 closedir(subdir);
(gdb)

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x00007fff8a736162 in closedir ()

(gdb) p subdir
$1 = (DIR *) 0x0

Moving the closedir command inside the brackets fixes the error.