summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2010-11-25 14:17:30 +0100
committerMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2010-11-25 14:17:30 +0100
commit042118c8cbc8e33fbff7e479f974d7571c413859 (patch)
tree558ebbdba4187ce2445fc296b34a0d56706acbac /sal
parentb82d9a8e18e8fada6a3d44ed4fa776bbf390654b (diff)
#i115784# sal: fix memory errors uncovered by valgrind and other tools.
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/file.cxx3
-rw-r--r--sal/osl/unx/file_misc.cxx6
-rw-r--r--sal/osl/unx/file_path_helper.cxx80
-rw-r--r--sal/osl/unx/process_impl.cxx19
-rw-r--r--sal/osl/unx/profile.c1
-rw-r--r--sal/osl/unx/socket.c39
6 files changed, 76 insertions, 72 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index cc0c041bc328..67f1d05660a8 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -215,7 +215,8 @@ FileHandle_Impl::Allocator::~Allocator()
void FileHandle_Impl::Allocator::allocate (sal_uInt8 ** ppBuffer, size_t * pnSize)
{
OSL_PRECOND((0 != ppBuffer) && (0 != pnSize), "FileHandle_Impl::Allocator::allocate(): contract violation");
- *ppBuffer = static_cast< sal_uInt8* >(rtl_cache_alloc(m_cache)), *pnSize = m_bufsiz;
+ if ((0 != ppBuffer) && (0 != pnSize))
+ *ppBuffer = static_cast< sal_uInt8* >(rtl_cache_alloc(m_cache)), *pnSize = m_bufsiz;
}
void FileHandle_Impl::Allocator::deallocate (sal_uInt8 * pBuffer)
{
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index 331b91cb1626..964a56336f8c 100644
--- a/sal/osl/unx/file_misc.cxx
+++ b/sal/osl/unx/file_misc.cxx
@@ -334,10 +334,8 @@ oslFileError SAL_CALL osl_getDirectoryItem( rtl_uString* ustrFileURL, oslDirecto
rtl_uString* ustrSystemPath = NULL;
oslFileError osl_error = osl_File_E_INVAL;
- OSL_ASSERT(ustrFileURL);
- OSL_ASSERT(pItem);
-
- if (0 == ustrFileURL->length || NULL == pItem)
+ OSL_ASSERT((0 != ustrFileURL) && (0 != pItem));
+ if ((0 == ustrFileURL) || (0 == ustrFileURL->length) || (0 == pItem))
return osl_File_E_INVAL;
osl_error = osl_getSystemPathFromFileURL_Ex(ustrFileURL, &ustrSystemPath, sal_False);
diff --git a/sal/osl/unx/file_path_helper.cxx b/sal/osl/unx/file_path_helper.cxx
index 04fdd13e7c15..9dd3b08493b0 100644
--- a/sal/osl/unx/file_path_helper.cxx
+++ b/sal/osl/unx/file_path_helper.cxx
@@ -73,19 +73,21 @@
void SAL_CALL osl_systemPathRemoveSeparator(rtl_uString* pustrPath)
{
- OSL_PRECOND(pustrPath, "osl_systemPathRemoveSeparator: Invalid parameter");
-
- // maybe there are more than one separator at end
- // so we run in a loop
- while ((pustrPath->length > 1) && (FPH_CHAR_PATH_SEPARATOR == pustrPath->buffer[pustrPath->length - 1]))
+ OSL_PRECOND(0 != pustrPath, "osl_systemPathRemoveSeparator: Invalid parameter");
+ if (0 != pustrPath)
{
- pustrPath->length--;
- pustrPath->buffer[pustrPath->length] = (sal_Unicode)'\0';
- }
+ // maybe there are more than one separator at end
+ // so we run in a loop
+ while ((pustrPath->length > 1) && (FPH_CHAR_PATH_SEPARATOR == pustrPath->buffer[pustrPath->length - 1]))
+ {
+ pustrPath->length--;
+ pustrPath->buffer[pustrPath->length] = (sal_Unicode)'\0';
+ }
- OSL_POSTCOND((0 == pustrPath->length) || (1 == pustrPath->length) || \
- (pustrPath->length > 1 && pustrPath->buffer[pustrPath->length - 1] != FPH_CHAR_PATH_SEPARATOR), \
- "osl_systemPathRemoveSeparator: Post condition failed");
+ OSL_POSTCOND((0 == pustrPath->length) || (1 == pustrPath->length) || \
+ (pustrPath->length > 1 && pustrPath->buffer[pustrPath->length - 1] != FPH_CHAR_PATH_SEPARATOR), \
+ "osl_systemPathRemoveSeparator: Post condition failed");
+ }
}
/*******************************************
@@ -94,21 +96,22 @@
void SAL_CALL osl_systemPathEnsureSeparator(rtl_uString** ppustrPath)
{
- OSL_PRECOND(ppustrPath && (NULL != *ppustrPath), \
- "osl_systemPathEnsureSeparator: Invalid parameter");
-
- rtl::OUString path(*ppustrPath);
- sal_Int32 lp = path.getLength();
- sal_Int32 i = path.lastIndexOf(FPH_CHAR_PATH_SEPARATOR);
-
- if ((lp > 1 && i != (lp - 1)) || ((lp < 2) && i < 0))
- {
- path += FPH_PATH_SEPARATOR();
- rtl_uString_assign(ppustrPath, path.pData);
- }
-
- OSL_POSTCOND(path.lastIndexOf(FPH_CHAR_PATH_SEPARATOR) == (path.getLength() - 1), \
- "osl_systemPathEnsureSeparator: Post condition failed");
+ OSL_PRECOND((0 != ppustrPath) && (0 != *ppustrPath), "osl_systemPathEnsureSeparator: Invalid parameter");
+ if ((0 != ppustrPath) && (0 != *ppustrPath))
+ {
+ rtl::OUString path(*ppustrPath);
+ sal_Int32 lp = path.getLength();
+ sal_Int32 i = path.lastIndexOf(FPH_CHAR_PATH_SEPARATOR);
+
+ if ((lp > 1 && i != (lp - 1)) || ((lp < 2) && i < 0))
+ {
+ path += FPH_PATH_SEPARATOR();
+ rtl_uString_assign(ppustrPath, path.pData);
+ }
+
+ OSL_POSTCOND(path.lastIndexOf(FPH_CHAR_PATH_SEPARATOR) == (path.getLength() - 1), \
+ "osl_systemPathEnsureSeparator: Post condition failed");
+ }
}
/*******************************************
@@ -117,8 +120,8 @@
sal_Bool SAL_CALL osl_systemPathIsRelativePath(const rtl_uString* pustrPath)
{
- OSL_PRECOND(pustrPath, "osl_systemPathIsRelativePath: Invalid parameter");
- return ((0 == pustrPath->length) || (pustrPath->buffer[0] != FPH_CHAR_PATH_SEPARATOR));
+ OSL_PRECOND(0 != pustrPath, "osl_systemPathIsRelativePath: Invalid parameter");
+ return ((0 == pustrPath) || (0 == pustrPath->length) || (pustrPath->buffer[0] != FPH_CHAR_PATH_SEPARATOR));
}
/******************************************
@@ -177,21 +180,16 @@
sal_Bool SAL_CALL osl_systemPathIsHiddenFileOrDirectoryEntry(
const rtl_uString* pustrPath)
{
- OSL_PRECOND(pustrPath, "osl_systemPathIsHiddenFileOrDirectoryEntry: Invalid parameter");
-
- sal_Bool is_hidden = sal_False;
+ OSL_PRECOND(0 != pustrPath, "osl_systemPathIsHiddenFileOrDirectoryEntry: Invalid parameter");
+ if ((0 == pustrPath) || (0 == pustrPath->length))
+ return sal_False;
- if (pustrPath->length > 0)
- {
- rtl::OUString fdp;
-
- osl_systemPathGetFileNameOrLastDirectoryPart(pustrPath, &fdp.pData);
-
- is_hidden = ((fdp.pData->length > 0) && (fdp.pData->buffer[0] == FPH_CHAR_DOT) &&
- !osl_systemPathIsLocalOrParentDirectoryEntry(fdp.pData));
- }
+ rtl::OUString fdp;
+ osl_systemPathGetFileNameOrLastDirectoryPart(pustrPath, &fdp.pData);
- return is_hidden;
+ return ((fdp.pData->length > 0) &&
+ (fdp.pData->buffer[0] == FPH_CHAR_DOT) &&
+ !osl_systemPathIsLocalOrParentDirectoryEntry(fdp.pData));
}
diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx
index e712b6748e7f..ee20c8552054 100644
--- a/sal/osl/unx/process_impl.cxx
+++ b/sal/osl/unx/process_impl.cxx
@@ -378,17 +378,20 @@ extern "C" int _imp_setProcessLocale( rtl_Locale * );
*********************************************/
oslProcessError SAL_CALL osl_getProcessLocale( rtl_Locale ** ppLocale )
{
+ oslProcessError result = osl_Process_E_Unknown;
OSL_PRECOND(ppLocale, "osl_getProcessLocale(): Invalid parameter.");
+ if (ppLocale)
+ {
+ pthread_mutex_lock(&(g_process_locale.m_mutex));
- pthread_mutex_lock(&(g_process_locale.m_mutex));
-
- if (g_process_locale.m_pLocale == 0)
- _imp_getProcessLocale (&(g_process_locale.m_pLocale));
- *ppLocale = g_process_locale.m_pLocale;
-
- pthread_mutex_unlock (&(g_process_locale.m_mutex));
+ if (g_process_locale.m_pLocale == 0)
+ _imp_getProcessLocale (&(g_process_locale.m_pLocale));
+ *ppLocale = g_process_locale.m_pLocale;
+ result = osl_Process_E_None;
- return (osl_Process_E_None);
+ pthread_mutex_unlock (&(g_process_locale.m_mutex));
+ }
+ return (result);
}
/**********************************************
diff --git a/sal/osl/unx/profile.c b/sal/osl/unx/profile.c
index c77a27543261..05d816c92755 100644
--- a/sal/osl/unx/profile.c
+++ b/sal/osl/unx/profile.c
@@ -514,7 +514,6 @@ sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile,
if ( pTmpProfile->m_bIsValid == sal_False )
{
- OSL_ASSERT(pProfile->m_bIsValid);
pthread_mutex_unlock(&(pTmpProfile->m_AccessLock));
#ifdef TRACE_OSL_PROFILE
OSL_TRACE("Out osl_readProfileString [not valid]\n");
diff --git a/sal/osl/unx/socket.c b/sal/osl/unx/socket.c
index c8faf6c028f5..2f7b62a4bfa4 100644
--- a/sal/osl/unx/socket.c
+++ b/sal/osl/unx/socket.c
@@ -605,16 +605,16 @@ sal_Bool SAL_CALL osl_isEqualSocketAddr (
oslSocketAddr Addr1,
oslSocketAddr Addr2)
{
- struct sockaddr* pAddr1= &(Addr1->m_sockaddr);
- struct sockaddr* pAddr2= &(Addr2->m_sockaddr);
-
- OSL_ASSERT(pAddr1);
- OSL_ASSERT(pAddr2);
-
- if (pAddr1->sa_family == pAddr2->sa_family)
+ OSL_ASSERT((0 != Addr1) && (0 != Addr2));
+ if ((0 != Addr1) || (0 != Addr2))
{
- switch (pAddr1->sa_family)
- {
+ struct sockaddr* pAddr1= &(Addr1->m_sockaddr);
+ struct sockaddr* pAddr2= &(Addr2->m_sockaddr);
+
+ if (pAddr1->sa_family == pAddr2->sa_family)
+ {
+ switch (pAddr1->sa_family)
+ {
case AF_INET:
{
struct sockaddr_in* pInetAddr1= (struct sockaddr_in*)pAddr1;
@@ -623,16 +623,16 @@ sal_Bool SAL_CALL osl_isEqualSocketAddr (
if ((pInetAddr1->sin_family == pInetAddr2->sin_family) &&
(pInetAddr1->sin_addr.s_addr == pInetAddr2->sin_addr.s_addr) &&
(pInetAddr1->sin_port == pInetAddr2->sin_port))
- return (sal_True);
+ return (sal_True);
}
default:
{
- return (memcmp(pAddr1, Addr2, sizeof(struct sockaddr)) == 0);
+ return (memcmp(pAddr1, pAddr2, sizeof(struct sockaddr)) == 0);
}
- }
+ }
+ }
}
-
return (sal_False);
}
@@ -1173,7 +1173,6 @@ oslHostAddr SAL_CALL osl_createHostAddr (
rtl_string_release(strHostname);
}
-
return HostAddr;
}
@@ -1197,7 +1196,7 @@ oslHostAddr SAL_CALL osl_psz_createHostAddr (
pHostAddr= (oslHostAddr) malloc(sizeof(struct oslHostAddrImpl));
OSL_ASSERT(pHostAddr);
- if (pAddr == NULL)
+ if (pHostAddr == NULL)
{
free (cn);
return ((oslHostAddr)NULL);
@@ -2530,7 +2529,10 @@ sal_Bool __osl_socket_poll (
int timeout;
int result;
- OSL_ASSERT(pSocket);
+ OSL_ASSERT(0 != pSocket);
+ if (0 == pSocket)
+ return sal_False; /* EINVAL */
+
pSocket->m_nLastError = 0;
fds.fd = pSocket->m_Socket;
@@ -2573,7 +2575,10 @@ sal_Bool __osl_socket_poll (
struct timeval tv;
int result;
- OSL_ASSERT(pSocket);
+ OSL_ASSERT(0 != pSocket);
+ if (0 == pSocket)
+ return sal_False; /* EINVAL */
+
pSocket->m_nLastError = 0;
FD_ZERO(&fds);