You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CFAllocatorSetDefault seems to work on a per-thread basis. E.g.:
$ cat p.mm
//===============================
#import <Foundation/Foundation.h>
#include <pthread.h>
void do_bad_stuff() {
NSURL *base = [[NSURL alloc] initWithString:@"file://localhost/Users/glider/Library/"];
NSURL *u = [[NSURL alloc] initWithString:@"Saved Application State" relativeToURL:base];
}
void *worker(void *_) {
#ifndef REPLACE_IN_MAIN_THREAD
CFAllocatorSetDefault(kCFAllocatorMallocZone);
#endif
do_bad_stuff();
return NULL;
}
int main() {
#ifdef REPLACE_IN_MAIN_THREAD
CFAllocatorSetDefault(kCFAllocatorMallocZone);
#endif
pthread_t th;
pthread_create(&th, NULL, worker, NULL);
pthread_join(th, NULL);
return 0;
}
//===============================
$ clang++ p.mm -o p -framework Foundation -DREPLACE_IN_MAIN_THREAD && ./p # Everything
fine
$ clang++ p.mm -o p -framework Foundation -UREPLACE_IN_MAIN_THREAD && ./p
p(54794,0x107281000) malloc: *** error for object 0x7ff7c8e002f8: pointer being freed
was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6
(this is an example from issue 70, which may stop working under ASan at once)
We need to reset the default CF allocator upon each thread creation.
Reported by ramosian.glider on 2012-06-19 20:08:31
The text was updated successfully, but these errors were encountered:
Originally reported on Google Code with ID 81
Reported by
ramosian.glider
on 2012-06-19 20:08:31The text was updated successfully, but these errors were encountered: