in reply to Re^4: XS: free() outside of the main thread causes crash on Windows
in thread XS: free() outside of the main thread causes crash on Windows

If you do this on win32 I don't get this "double free" error
#include <pthread.h> void *thread(void *arg) { char *msg = (char*)arg; printf("thread: %s\n", msg); free(msg); return NULL; } #include "EXTERN.h" ...
  • Comment on Re^5: XS: free() outside of the main thread causes crash on Windows
  • Download Code

Replies are listed 'Best First'.
Re^6: XS: free() outside of the main thread causes crash on Windows
by OlegG (Monk) on Sep 25, 2014 at 08:27 UTC
    And gdb output looks not very usefull
    (gdb) r t.pl Starting program: C:\Perl64\bin\perl.exe t.pl [New Thread 17748.0x6114] [New Thread 17748.0x61f8] thread: Just another XS hacker warning: Critical error detected c0000374 Program received signal SIGTRAP, Trace/breakpoint trap. [Switching to Thread 17748.0x61f8] 0x00000000770d40d0 in ntdll!RtlUnhandledExceptionFilter () from C:\WINDOWS\SYSTEM32\ntdll.dll (gdb) bt #0 0x00000000770d40d0 in ntdll!RtlUnhandledExceptionFilter () from C:\WINDOWS\SYSTEM32\ntdll.dll #1 0x00000000770d4746 in ntdll!EtwEnumerateProcessRegGuids () from C:\WINDOWS\SYSTEM32\ntdll.dll #2 0x00000000770d5952 in ntdll!RtlQueryProcessLockInformation () from C:\WINDOWS\SYSTEM32\ntdll.dll #3 0x00000000770d7604 in ntdll!RtlLogStackBackTrace () from C:\WINDOWS\SYSTEM32\ntdll.dll #4 0x000000007707dc47 in ntdll!RtlIsDosDeviceName_U () from C:\WINDOWS\SYSTEM32\ntdll.dll Backtrace stopped: previous frame inner to this frame (corrupt stack?) (gdb)
Re^6: XS: free() outside of the main thread causes crash on Windows
by OlegG (Monk) on Sep 25, 2014 at 08:19 UTC
    I changed it to
    #include <pthread.h> void *thread(void *arg) { char *msg = (char*)arg; printf("thread: %s\n", msg); free(msg); return NULL; } #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" MODULE = My PACKAGE = My void test_thread(char *msg) PPCODE: char *thread_arg = malloc((strlen(msg)+1)*sizeof(char)); strcpy(thread_arg, msg); pthread_t tid; pthread_create(&tid, NULL, thread, (void*)thread_arg); void *rv; pthread_join(tid, &rv);

    And the problem still here: crash on each run

      And the problem still here: crash on each run

      No problem for me I got citrusperl 5.16.1 with

      $ gcc --version gcc (gcc-4.6.3 release with patches [build 20121012 by perlmingw.sf.ne +t]) 4.6.3 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There i +s NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR +POSE.
        I am testing on ActiveState perl