7176138: Fixes for missing close() calls and possible null pointer reference instead of fatal error

Reviewed-by: dcubed
This commit is contained in:
Kelly O'Hair 2012-06-12 13:54:20 -07:00
parent c419fa6171
commit a4bc0fa013
2 changed files with 11 additions and 5 deletions

View File

@ -120,7 +120,7 @@ typedef struct LookupTable {
TableIndex table_incr; /* Suggested increment size. */
TableIndex hash_bucket_count; /* Number of hash buckets. */
int elem_size; /* Size of element. */
int info_size; /* Size of info structure. */
int info_size; /* Size of info structure (can be 0). */
void *freed_bv; /* Freed element bit vector */
int freed_count; /* Count of freed'd elements */
TableIndex freed_start; /* First freed in table */
@ -208,9 +208,6 @@ get_info(LookupTable *ltable, TableIndex index)
{
TableElement *element;
if ( ltable->info_size == 0 ) {
return NULL;
}
element = (TableElement*)ELEMENT_PTR(ltable,index);
return element->info;
}
@ -760,7 +757,11 @@ table_walk_items(LookupTable *ltable, LookupTableIterator func, void* arg)
void *info;
get_key(ltable, index, &key_ptr, &key_len);
info = get_info(ltable, index);
if ( ltable->info_size == 0 ) {
info = NULL;
} else {
info = get_info(ltable, index);
}
(*func)(SANITY_ADD_HARE(index, ltable->hare), key_ptr, key_len, info, arg);
if ( is_freed_entry(ltable, index) ) {
fcount++;

View File

@ -119,9 +119,13 @@ md_connect(char *hostname, unsigned short port)
/* create a socket */
fd = socket(AF_INET, SOCK_STREAM, 0);
if ( fd < 0 ) {
return -1;
}
/* find remote host's addr from name */
if ((hentry = gethostbyname(hostname)) == NULL) {
(void)close(fd);
return -1;
}
(void)memset((char *)&s, 0, sizeof(s));
@ -134,6 +138,7 @@ md_connect(char *hostname, unsigned short port)
/* now try connecting */
if (-1 == connect(fd, (struct sockaddr*)&s, sizeof(s))) {
(void)close(fd);
return 0;
}
return fd;