Sponsored Content
Operating Systems Solaris application Crashes on memset ?? any suggestions Post 302360614 by sudharma on Friday 9th of October 2009 12:56:07 PM
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.
Code:
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));
    sock_no=0;
   *socky=0;

   /* 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(hRes)
     free(hRes);

    if (hp==NULL)
    {
        *socky=0;
        return(-1);
    }

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
Code:
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
Sudharma

Last edited by pludi; 10-09-2009 at 03:34 PM.. Reason: code tags, please
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
GETHOSTBYNAME(3)					     Linux Programmer's Manual						  GETHOSTBYNAME(3)

NAME
gethostbyname, gethostbyaddr, sethostent, endhostent, herror, hstrerror - get network host entry SYNOPSIS
#include <netdb.h> extern int h_errno; struct hostent *gethostbyname(const char *name); #include <sys/socket.h> /* for AF_INET */ struct hostent *gethostbyaddr(const char *addr, int len, int type); void sethostent(int stayopen); void endhostent(void); void herror(const char *s); const char *hstrerror(int err); /* GNU extensions */ struct hostent *gethostbyname2(const char *name, int af); int gethostbyname_r (const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); int gethostbyname2_r (const char *name, int af, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); DESCRIPTION
The gethostbyname() function returns a structure of type hostent for the given host name. Here name is either a host name, or an IPv4 address in standard dot notation, or an IPv6 address in colon (and possibly dot) notation. (See RFC 1884 for the description of IPv6 addresses.) If name is an IPv4 or IPv6 address, no lookup is performed and gethostbyname() simply copies name into the h_name field and its struct in_addr equivalent into the h_addr_list[0] field of the returned hostent structure. If name doesn't end in a dot and the envi- ronment variable HOSTALIASES is set, the alias file pointed to by HOSTALIASES will first be searched for name (see hostname(7) for the file format). The current domain and its parents are searched unless name ends in a dot. The gethostbyaddr() function returns a structure of type hostent for the given host address addr of length len and address type type. The only valid address type is currently AF_INET. The sethostent() function specifies, if stayopen is true (1), that a connected TCP socket should be used for the name server queries and that the connection should remain open during successive queries. Otherwise, name server queries will use UDP datagrams. The endhostent() function ends the use of a TCP connection for name server queries. The (obsolete) herror() function prints the error message associated with the current value of h_errno on stderr. The (obsolete) hstrerror() function takes an error number (typically h_errno) and returns the corresponding message string. The domain name queries carried out by gethostbyname() and gethostbyaddr() use a combination of any or all of the name server named(8), a broken out line from /etc/hosts, and the Network Information Service (NIS or YP), depending upon the contents of the order line in /etc/host.conf. (See resolv+(8)). The default action is to query named(8), followed by /etc/hosts. The hostent structure is defined in <netdb.h> as follows: struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses */ } #define h_addr h_addr_list[0] /* for backward compatibility */ The members of the hostent structure are: h_name The official name of the host. h_aliases A zero-terminated array of alternative names for the host. h_addrtype The type of address; always AF_INET at present. h_length The length of the address in bytes. h_addr_list A zero-terminated array of network addresses for the host in network byte order. h_addr The first address in h_addr_list for backward compatibility. RETURN VALUE
The gethostbyname() and gethostbyaddr() functions return the hostent structure or a NULL pointer if an error occurs. On error, the h_errno variable holds an error number. ERRORS
The variable h_errno can have the following values: HOST_NOT_FOUND The specified host is unknown. NO_ADDRESS or NO_DATA The requested name is valid but does not have an IP address. NO_RECOVERY A non-recoverable name server error occurred. TRY_AGAIN A temporary error occurred on an authoritative name server. Try again later. FILES
/etc/host.conf resolver configuration file /etc/hosts host database file CONFORMING TO
BSD 4.3. NOTES
The SUS-v2 standard is buggy and declares the len parameter of gethostbyaddr() to be of type size_t. (That is wrong, because it has to be int, and size_t is not. POSIX 1003.1-2001 makes it socklen_t, which is OK.) The functions gethostbyname() and gethostbyaddr() may return pointers to static data, which may be overwritten by later calls. Copying the struct hostent does not suffice, since it contains pointers - a deep copy is required. Glibc2 also has a gethostbyname2() that works like gethostbyname(), but permits to specify the address family to which the address must belong. Glibc2 also has reentrant versions gethostbyname_r() and gethostbyname2_r(). These return 0 on success and nonzero on error. The result of the call is now stored in the struct with address ret. After the call, *result will be NULL on error or point to the result on success. Auxiliary data is stored in the buffer buf of length buflen. (If the buffer is too small, these functions will return ERANGE.) No global variable h_errno is modified, but the address of a variable in which to store error numbers is passed in h_errnop. POSIX 1003.1-2001 marks gethostbyaddr() and gethostbyname() legacy, and introduces struct hostent *getipnodebyaddr (const void *restrict addr, socklen_t len, int type, int *restrict error_num); struct hostent *getipnodebyname (const char *name, int type, int flags, int *error_num); SEE ALSO
resolver(3), hosts(5), hostname(7), resolv+(8), named(8) BSD
2000-08-12 GETHOSTBYNAME(3)
All times are GMT -4. The time now is 01:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy