
=6789= Address 0xbd9670d0 is on thread 1's stack =6789= Use of uninitialised value of size 4 =6789= Conditional jump or move depends on uninitialised value(s) =6789= Using Valgrind-3.15.0 and LibVEX rerun with -h for copyright info =6789= Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. The result executing your program under valgrind : $ valgrind. For instance in main the array s only contains the characters '2' and '3' and is not terminated by the null character, so strlen(digits) has an undefined behavior reading after s, just do char s = "23" to avoid that. This is because main call letterCombinations with NULL for returnSize so in : *returnSize = resLen // set breakpoint hereĪnyway before you have a lot of undefined behaviors accessing non initialized values. " when it reach the next line of breakpoint - return result. "Program terminated with signal SIGSEGV, Segmentation fault. I need some help to show me where the problem is. I check the value of result at the line just before return result, it seems okay. *returnSize = resLen // set breakpoint hereĬhar ** outcome = letterCombinations(digits, returnSize) Result = (char *)malloc(strlen(tmp) + 1) Ĭhar *phoneData = phone - '0' - 2] įor (int i = 0 i < strlen(phoneData) i++) Ĭhar **result = (char **)malloc(sizeof(char *) * 40) ĬatRes(result, phone, digits, tmp, 0, &resLen) Void catRes(char **result, char **phone, char *digits, char *tmp, int nowIndex, Yet when I want to test on my local machine, I met a problem "Program terminated with signal SIGSEGV, Segmentation fault. # _async_raise( submit it online, and it passed the test. _async_raise(self._get_my_tid(), exctype ) The following fixes that and uses a custom Exception subclass to make things more clear: import threading If you do just that, however, you'll get an Exception in thread Thread-1: because there's no exception handler in the work() function to handle the exception that gets raised by raiseExc(). I think the fundamental problem you have is that you're not calling _async_raise() correctly and should replace the line: _async_raise((TypeError)) I also tried threading.get_ident() instead of the answer's _get_my_tid() that gives me another ID but that one is also invalid. This gives a ValueError: invalid thread id exception. _async_raise( self._get_my_tid(), exctype ) Raise AssertionError("could not determine the thread's id") Raise threading.ThreadError("the thread is not active")įor tid, tobj in threading._ems():

Raise SystemError("PyThreadState_SetAsyncExc failed") Res = _SetAsyncExc(tid,Ĭ_SetAsyncExc(tid, 0) Raise TypeError("Only types can be raised (not instances)") NB: _async_raise and ThreadWithExc are copy/pastes of the accepted answer to this question on SO: import threading I have a class that spawns a thread and that thread should be stopped externally (the thread never finishes naturally, as in this example).

I've tried to implement the simplest case that corresponds to my circumstances. This question has been answered before and I'm trying to implement the second solution in the first answer outlined here (NB: the first solution does not concern me, my thread is running a server from an external library and can't be modified to check a flag)
