Check The value a pointer returned by struct s_client != 0
Hi guys ,
i got segment fault , and when i trace , found it happens since the value of pointer which is returned by Struct S_client (*ptr) is zero
i know , adding above line of code is not the solution and not correct for the case since above line only check for the pointer to the address of memory which is not expected for me, i would like to check the value of ptr which is returned in struct s_client , not be zero . so anyone know how could i do that , is appreciated?
Here is the c programming code :
Best Regards.
---------- Post updated at 11:08 AM ---------- Previous update was at 10:39 AM ----------
i think , pthread_getspecific is the case ...
also in man page (qoute from here) :
Quote:
If pthread_getspecific is called on the key whose thread specific data is being destroyed, the value NULL is returned, unless pthread_setspecific was called previously on that key from within destr_function to set the value to non-NULL.
Since ptr previously might be destroyed (so using if (ptr != 0) ) could not fix the problem , Does anyone know any solution for this problem , i don't know how with pthread_setspecific or any other trick could bypass this segmentation fault.
the reason that i said ptr !=0 is not correct , since i tried with above codes , and still with the if statement i get zero vaule for ptr... (probably because pthread_getspecific , destroyed it before..
There are many reasons it could be returning NULL, for instance, if it was never set in the first place, or used before the main thread managed to set it (race condition), or the main thread had a problem setting it(bug, out of memory), etc.
You can't simply "bypass" it. If it's checking for data there, it's looking for data the programmer was trying to provide it explicitly, and must need it. Investigate where the thread-specific data gets set in the first place, and see if there's ever a glitch in that -- check its return values, make sure the data being fed into it is sane, etc, etc.
I suppose for a really hacky fix, you could check if the data returned was NULL, wait a millisecond with usleep, and try again up to a maximum of 3 or 4 times, just in case the data hasn't been set yet, but that would reveal deeper fundamental issues with the program...
Last edited by Corona688; 09-14-2012 at 02:05 PM..
Hi all!
I am trying to register a device in an existing device class, but I am
having trouble getting the pointer to an existing class.
I can create a class in a module, get the pointer to it and then use
it to register the device with:
*cl = class_create(THIS_MODULE, className);... (0 Replies)
I have a uint8_t *C = malloc(24*sizeof(uint8_t));
I need to send some integers and this *C to another node(in ad hoc network). So I am going to use a struct
` struct fulMsg {
int msgType;
int msgCount;
//uint8_t *CC;
} fulMsg_t;
typedef struct fulMsg fulMsg_tt;`
there is a method... (1 Reply)
Hi all,
I am wondering how can I check when a variable has nothing returned in it. I am trying to store a pid in this variable to see if a script is running in the background. So I am using something like that
proc_pid=`ps -ef |grep script.sh|grep -v grep|awk '{print $2}'`
if
then
... (1 Reply)
Hi,
I have received an application that stores some properties in a file. The existing struct looks like this:
struct TData
{
UINT uSizeIncludingStrings;
// copy of Telnet data struct
UINT uSize;
// basic properties:
TCHAR szHost; //defined in Sshconfig
UINT iPortNr;
TCHAR... (2 Replies)
can someone provide an example of a struct linked list, where it has strings as its values, and then how do I check if a specific string (say called buffer) exists in the list of structs?
i dont understand how to make a copy of it to check with
this is what i have
... (0 Replies)
I have what should be a relatively simple program (fadec.c) that maps a struct from an included header file (fadec.h) to a shared memory region, but I’m struggling accessing members in the struct from the pointer returned by shmat. Ultimately, I want to access members in the shared memory structure... (2 Replies)
Suppose to have:
struct Tstudent
{
string name, surname;
int matriculation_num;
};
struct Tnode
{
Tstudent* student;
Tnodo* next;
} L;I want to deference that "student" pointer. For example, I tried with:
*(L->student).matriculation_numbut it not worked, as terminal... (4 Replies)
HI,
Am not able to close open ssl session once after excuting the s_client command.Please help me.
Find below command which am using in my script:
=====================================
openssl s_client -connect localhost:443 -debug >/tmp/tempfile.txt 2>&1
after this can you please... (2 Replies)
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
I am using a structure defined as follows
struct gene_square
{
double *x;
double *y;
};I have class, with a member function which is a pointer of this type:
gene_square* m_Genes;I am allocating memory in the constructors like this:
m_Genes = new gene_square;
for (ii=0;... (1 Reply)