Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pacers721

macrumors member
Original poster
Jul 30, 2008
61
0
Whenever I call readdir before I create a thread, I get an error that looks like this:
perl(2820,0x7fff70c33ca0) malloc: *** error for object 0x10082e600: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap

What's strange is that it happens when I call readdir before I create a thread (i.e. readdir is not called in any concurrent code). I don't even use the results from readdir, just making the call to it seems to screw things up. When I get rid of it, things seem to work fine. Some example code is below:

opendir(DIR, $someDir);
my @allFiles = readdir(DIR);
close(DIR);

my $thread = threads->create(\&sub1);
$thread->join();

sub sub1 {
print "in thread\n"
}
 
I would try calling "closedir(DIR)" instead of "close(DIR)".

perldoc -f opendir

... it's quite clear about that.

I reproduced the issue with your code on Linux. And closedir() did indeed fix the issue on my box.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.