develooper Front page | perl.vmsperl | Postings from March 2006

Threads and safesysfree?

Thread Next
From:
John E. Malmberg
Date:
March 7, 2006 19:50
Subject:
Threads and safesysfree?
Message ID:
440E5495.8030207@qsl.net
As I am troubleshooting an issue with threads and memory allocation on 
OpenVMS, I have noticed a couple of things.

In util.c the routines Perl_safesysmalloc and friends are updating a 
linked list.

There does not seem to be any protection from a different thread also 
updating the same linked list at the same time, especially on a 
multi-processor system.

I would recommend that either a static routine or macro be used to 
insert and remove elements from the linked list, and when a threaded 
perl is being built, it compile in taking out a thread mutex during the 
operation.


Since normally the header->interpreter value is not poisoned when memory 
is free, if something else mallocs the memory right after a free 
operation, and then incorrectly calls Perl_safesysfree() to free it, 
this will not be detected by Perl_safesysfree.

I just hit this condition because of a bug I introduced into my test 
vms/vms.c, where Perl_safesysfree(free) successfully freed memory that 
was allocated by malloc().

I would recommend that the header->interpreter value always be poisoned 
so that this condition can be better detected.

-John
wb8tyw@qsl.net
Personal Opinion Only



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About