summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhu, Yongsheng <yongsheng.zhu@intel.com>2010-05-27 17:36:00 +0800
committerPatrick Ohly <patrick.ohly@intel.com>2010-05-31 13:02:35 +0200
commit3ba8fbfcc480cffc8d427e686b9b3a0e3d327f41 (patch)
tree0af3903d5c1ca84c72815bd4e8b1d3e5d6073f55
parent10afbd097c2d203c5cfca98abc68645c83908dd5 (diff)
valgrind issues: fix memory issues reported by valgrindmbc1007
valgrind reports many memory issues about reading uninitialised values. These values may cause random crashes. There are 3 situations: 1) The macros make some variables uninitialised 2) Not all members of a struct are initialised 3) Read value over the volume of allocated buffers
-rwxr-xr-xsrc/sysync/binfileimplds.cpp8
-rwxr-xr-xsrc/sysync/stringutils.cpp4
-rwxr-xr-xsrc/sysync/syncagent.cpp10
3 files changed, 17 insertions, 5 deletions
diff --git a/src/sysync/binfileimplds.cpp b/src/sysync/binfileimplds.cpp
index 355f971..8a61a36 100755
--- a/src/sysync/binfileimplds.cpp
+++ b/src/sysync/binfileimplds.cpp
@@ -303,6 +303,8 @@ void TBinfileDSConfig::initTarget(
bool aEnabled // enabled?
)
{
+ //set to zeros to avoid memory warnings
+ memset(&aTarget, 0, sizeof(aTarget));
// link to the profile
aTarget.remotepartyID=aRemotepartyID;
// enabled or not?
@@ -606,7 +608,8 @@ bool TBinfileImplDS::openChangeLog(void)
// create new change log or overwrite incompatible one
// - init changelog header fields
fChgLogHeader.modcount=0;
- AssignCString(fChgLogHeader.lastChangeCheckIdentifier,NULL,0);
+ //set all bytes to zero to avoid memory warnings
+ memset(fChgLogHeader.lastChangeCheckIdentifier, 0, changeIndentifierMaxLen);
fChgLogHeader.lastChangeCheck = noLinearTime;
// - create new changelog
fChangeLog.create(sizeof(TChangeLogEntry),sizeof(TChangeLogHeader),&fChgLogHeader,true);
@@ -708,6 +711,8 @@ localstatus TBinfileImplDS::changeLogPreflight(bool &aValidChangelog)
uInt32 seen=0;
uInt32 logindex;
TChangeLogEntry newentry;
+ //set zeros to avoid memory warnings
+ memset(&newentry, 0, sizeof(newentry));
TSyncItem *itemP = NULL;
localid_out_t itemLocalID;
uInt16 dataCRC = 0;
@@ -2247,6 +2252,7 @@ localstatus TBinfileImplDS::SaveAdminData(bool aSessionFinished, bool aSuccessfu
// make sure that resume alert codes of all other profile's targets for this datastore are erased
// (because we have only a single changelog (markforresume flags!) and single pendingmap+pendingitem files)
TBinfileDBSyncTarget otherTarget;
+ memset(&otherTarget, 0, sizeof(otherTarget));
for (sInt32 ti=0; ti<sInt32(targetsBinFileP->getNumRecords()); ti++) {
if (ti!=fTargetIndex) {
// get that target
diff --git a/src/sysync/stringutils.cpp b/src/sysync/stringutils.cpp
index a3660d6..958a4bd 100755
--- a/src/sysync/stringutils.cpp
+++ b/src/sysync/stringutils.cpp
@@ -489,7 +489,9 @@ sInt16 HexStrToUShort(const char *aStr, uInt16 &aShort, sInt16 aMaxDigits)
char c;
sInt16 n=0;
aShort=0;
- while (aStr && (c=*aStr++) && (n<aMaxDigits)) {
+ //firstly check aMaxDigits to avoid accessing invalid value of 'aStr'
+ //This will cause a memory warning checked by valgrind
+ while ((n<aMaxDigits) && aStr && (c=*aStr++)) {
if (!isxdigit(c)) break;
aShort<<=4;
aShort+=(toupper(c)-0x30);
diff --git a/src/sysync/syncagent.cpp b/src/sysync/syncagent.cpp
index 5759d91..f31796a 100755
--- a/src/sysync/syncagent.cpp
+++ b/src/sysync/syncagent.cpp
@@ -631,6 +631,10 @@ TSyncAgent::TSyncAgent(
// - issue session start event here (in non-engine case this is done in TSyncSession constructor)
SESSION_PROGRESS_EVENT(this,pev_sessionstart,NULL,0,0,0);
#endif // ENGINE_LIBRARY
+ // reset data counts
+ fIncomingBytes = 0;
+ fOutgoingBytes = 0;
+
// Specific for Client or Server
if (IS_CLIENT) {
#ifdef SYSYNC_CLIENT
@@ -652,9 +656,6 @@ TSyncAgent::TSyncAgent(
// init answer buffer
fBufferedAnswer = NULL;
fBufferedAnswerSize = 0;
- // reset data counts
- fIncomingBytes = 0;
- fOutgoingBytes = 0;
#ifdef ENGINE_LIBRARY
// engine
fServerEngineState = ses_needdata;
@@ -1708,6 +1709,9 @@ void TSyncAgent::retryClientSessionStart(bool aOldMessageInBuffer)
// create a RespURI string. If none needed, return NULL
SmlPcdataPtr_t TSyncAgent::newResponseURIForRemote(void)
{
+ if (IS_CLIENT) {
+ return NULL;
+ }
// do it in a transport-independent way, therefore let dispatcher do it
string respURI; // empty string
if (fUseRespURI) {