application Crashes on memset ?? any suggestions

Thread Tools Search this Thread
Operating Systems Solaris application Crashes on memset ?? any suggestions
# 1  
Old 10-09-2009
application Crashes on memset ?? any suggestions

Hi All,

we have an application that is written in 'C' programming to connects to various servers in the organization.

The bellow code establish a TCP connection to connect to the remote servers. the application works perfectly ok, but, after some time the entire process get's crashed and dumps a core file. after doing some investigation i found that it crashing when calling a memset function. Please note the entire code is a multi- threaded programming.
int establist_connection(thrd_no, host_name, serv_name, socky, port_no, retry)
int  thrd_no;
char *host_name;
char *serv_name;
int *socky;
int *port_no;
int retry;
    struct sockaddr_in serv_add = {0};
    struct sockaddr_in myaddr_in = {0};
    struct hostent *hp = NULL;
    struct servent *sp = NULL;
    struct servent *sRes = NULL;
    struct hostent *hRes = NULL;
    char servBuf[1024];
    char hostBuf[1024];
    int errnop = 0;

   memset ((char *) &serv_add, 0, sizeof(struct sockaddr_in));

   /* set up server address structure */
    serv_add.sin_family = AF_INET;

   /* get the remote host information to establish address for server */

   hRes = (struct hostent *)malloc(sizeof(struct hostent));
   hp = gethostbyname_r(host_name, hRes, hostBuf, sizeof(hostBuf), &errnop);


    if (hp==NULL)

The core shows that the application crashes imdeatly after the gethostbyname_r function is executed, that means it's failing when it's trying to free hRes memory
core DUM
detected a multithreaded program
t@24988 (l@24988) terminated by signal BUS (invalid address alignment)
0x0001d638: establist_connection+0x0108:    ld      [%l0], %l0

dbx: internal error: signal SIGSEGV (no mapping at the fault address)
dbx's coredump will appear in /tmp

Can you please help me with this ... when i google'd around i found some posts that memset could cause the segmentation fault error on Solaris OS. Please share your thoughts on this.

Thank you

Last edited by pludi; 10-09-2009 at 04:34 PM.. Reason: code tags, please
# 2  
Old 10-09-2009
Originally Posted by sudharma
Can you please help me with this ... when i google'd around i found some posts that memset could cause the segmentation fault error on Solaris OS.
Memset is just doing what it is asked for. If a segfault occurs, it's not memset but some bug in your code or a library you use which is more likely to blame.

As you are using dbx, did you try its run time checking functionalities to figure out what is causing that issue ?

See that blog for details on how to enable it: Runtime Memory Checking : Leonard Li's Weblog
# 3  
Old 10-13-2009
Thanks a lot jlliagre
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

Memset fails on Solaris

Hi, memset call is failing on solaris for me. I wrote below code and that also fails. Any hints? void *memset(void *dst, int c, size_t n) { if (n) { char *d = dst; do { *d++ = c; } while (--n); } return dst; } (2 Replies)
Discussion started by: skyineyes
2 Replies

2. Shell Programming and Scripting

Suggestions for technology used for an application

I want to develop an application. Simply, Open this application via the web Access database to retrieve some information Do some validation and process inputs Create a file based on a master file from a UNIX server Put that file to the UNIX server That is it. I have got suggestions to... (5 Replies)
Discussion started by: PikK45
5 Replies

3. Solaris

Server crashes when not in use.

Production server crashes when there is no traffic on it. Can only recover by going to ALOM and reboot the server. This seems to happen about the same time every month. The only good thing is the server is not in production at the time of the crash. I have been unable to locate any information in... (5 Replies)
Discussion started by: Joeentech
5 Replies

4. UNIX for Advanced & Expert Users

motif application crashes while calling XtDestroyWidget

Hi All, We have a 32bit Motif Gui application. Now we ported the application from Solaris to Linux and the system is crashing very frequently. On our analysis we could find that this issue happened when we are closing the forms in our application. When the forms are closed we will delete the forms... (0 Replies)
Discussion started by: sanushchacko
0 Replies

5. Programming

C++ program crashes

Hi, Could anyone tell me the reason why the following program crashes? class A { int x; public: A() { cout << "from A()" << endl; } ~A() { cout << "from ~A()" << endl; } }; class B : public A { public: B() { cout << "from B()"... (2 Replies)
Discussion started by: royalibrahim
2 Replies

6. Programming

C bzero() to memset() issue

Hi guys, my tool works fine in gentoo, ubuntu now im trying to port it to windows but bzero/bcopy I read aren't working on windows and for better portability I should of use memset() so im trying to translate bzero(buffer,256);in printf("MAIL TO"); strcpy(buffer, rcp); ... (4 Replies)
Discussion started by: Jess83
4 Replies

7. Programming

Application crashes in FreeBSD 7.1 while working ok in FreeBSD 6.3

Hello there, My mulithreaded application (which is too large to represent the source code here) is crashing after installing FreeBSD 7.1-RELEASE/amd64. It worked properly on others machines (Dual Cores with 4GB of RAM - FreeBSD 6.2-RELEASE/i386). The current machine has 2x Core 2 Duo... (1 Reply)
Discussion started by: Seenquev
1 Replies

8. UNIX for Advanced & Expert Users

memset vs calloc

Dear Friends, Can any one tell me the difference between memset and calloc function in C. Regards, Selvi (7 Replies)
Discussion started by: salvi
7 Replies

9. UNIX for Dummies Questions & Answers

questions in memset

HI all , please find the piece of code below char *t; char *f; char buf; memset(buf,0,50); after that i am assigning memory for (i=0; i<100; i++) { t = buf+(i*6); f = "ARUN"; } my question .. 1) i have run this it is... (7 Replies)
Discussion started by: arunkumar_mca
7 Replies

10. Programming

about memset fuction

Dear all, In my code,i am planning to use memset function to re-initialise an array before populating it everytime. Will using memset function be an overload to the program? (3 Replies)
Discussion started by: ranj@chn
3 Replies
Login or Register to Ask a Question