From: Peter Howkins Date: Mon, 2 Apr 2018 21:10:46 +0000 (+0100) Subject: libdtsvc: Resolve coverity warnings related to 'dereference before null check' relate... X-Git-Tag: 2.2.4a~134 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=acc3d8868a76b971833fcbede1a76249851a4f31;p=oweals%2Fcde.git libdtsvc: Resolve coverity warnings related to 'dereference before null check' related to free() --- diff --git a/cde/lib/DtSvc/DtEncap/connect.c b/cde/lib/DtSvc/DtEncap/connect.c index 2338f167..83f1087f 100644 --- a/cde/lib/DtSvc/DtEncap/connect.c +++ b/cde/lib/DtSvc/DtEncap/connect.c @@ -418,7 +418,7 @@ Xegetcwd(char *buf, int size) env = XeMalloc(MAXPATHLEN+10); sprintf(env, "PWD=%s", buf); copying_putenv(env); /* set PWD if necessary for later cache use */ - if (env) XeFree(env); + XeFree(env); } return current_dir; } @@ -448,7 +448,7 @@ Xechdir (const char *path) } copying_putenv(env); /* update PWD if directory changed */ - if (env) XeFree(env); + XeFree(env); } return status; } diff --git a/cde/lib/DtSvc/DtEncap/noio.c b/cde/lib/DtSvc/DtEncap/noio.c index 14121a8d..409cd4f1 100644 --- a/cde/lib/DtSvc/DtEncap/noio.c +++ b/cde/lib/DtSvc/DtEncap/noio.c @@ -234,8 +234,7 @@ SPC_Channel_Ptr open_noio_channel_object(SPC_Channel_Ptr channel, else { temp_dir_name = get_tmp_dir (); channel->logfile=tempnam(temp_dir_name,"SPC"); - if (temp_dir_name != NULL) - free(temp_dir_name); + free(temp_dir_name); } /* diff --git a/cde/lib/DtSvc/DtUtil1/Action.c b/cde/lib/DtSvc/DtUtil1/Action.c index 5e3e90f6..0e546434 100644 --- a/cde/lib/DtSvc/DtUtil1/Action.c +++ b/cde/lib/DtSvc/DtUtil1/Action.c @@ -1091,7 +1091,7 @@ NoActionError( _DtCreateErrorDialog(w, actionName, msg); XmStringFree(msg); - if (msgbuf) XtFree(msgbuf); + XtFree(msgbuf); XtFree(name); } @@ -1158,7 +1158,7 @@ TmpFileCreateError( Widget w, char *actionName, char *dirName) msg = XmStringCreateLocalized(msgbuf); _DtCreateErrorDialog(w, actionName, msg); XmStringFree(msg); - if (msgbuf) XtFree(msgbuf); + XtFree(msgbuf); } static void @@ -1173,7 +1173,7 @@ TmpFileOpenError( Widget w, char *actionName, char *fileName) msg = XmStringCreateLocalized(msgbuf); _DtCreateErrorDialog(w, actionName, msg); XmStringFree(msg); - if (msgbuf) XtFree(msgbuf); + XtFree(msgbuf); } static void @@ -1188,7 +1188,7 @@ TmpFileWriteError( Widget w, char *actionName, char *fileName) msg = XmStringCreateLocalized(msgbuf); _DtCreateErrorDialog(w, actionName, msg); XmStringFree(msg); - if (msgbuf) XtFree(msgbuf); + XtFree(msgbuf); } static void @@ -1202,7 +1202,7 @@ UnSupportedObject( Widget w, char *actionName, int objClass) msg = XmStringCreateLocalized(msgbuf); _DtCreateErrorDialog(w, actionName, msg); XmStringFree(msg); - if (msgbuf) XtFree(msgbuf); + XtFree(msgbuf); } diff --git a/cde/lib/DtSvc/DtUtil1/ActionDb.c b/cde/lib/DtSvc/DtUtil1/ActionDb.c index ebde6c9f..0b6e6350 100644 --- a/cde/lib/DtSvc/DtUtil1/ActionDb.c +++ b/cde/lib/DtSvc/DtUtil1/ActionDb.c @@ -379,8 +379,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, val, _DtACTION_TYPE); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } break; @@ -411,8 +411,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, start, _DtACTION_ARG_CLASS); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } *p = _DtACT_LIST_SEPARATOR_CHAR; @@ -429,8 +429,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, start, _DtACTION_ARG_CLASS); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } break; @@ -445,7 +445,7 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, val, _DtACTION_ARG_MODE); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); + free(val); buf = malloc(_DtAct_MAX_BUF_SIZE); return NULL; } @@ -474,8 +474,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) filename, val, _DtACTION_ARG_COUNT); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } } @@ -492,8 +492,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, val, _DtACTION_WINDOW_TYPE); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if (val) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } break; @@ -534,8 +534,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, val, _DtACTION_CWD); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); /********************* reject the entire record containing this field *********************/ @@ -549,8 +549,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, val, _DtACTION_CWD); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if (val) free(val); - if (buf) free(buf); + free(val); + free(buf); /********************* reject the entire record containing this field *********************/ @@ -568,8 +568,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, val, _DtACTION_TT_CLASS); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } break; @@ -586,8 +586,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) (void) sprintf(buf, unrecogMsgType, actName, filename, val, _DtACTION_TT_SCOPE); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } break; @@ -616,8 +616,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) val, _DtACTION_TTN_ARG, "n", _DtACTION_TTN_MODE); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } break; @@ -647,8 +647,8 @@ _DtActValidateFieldValue( long bit, char *value, char *actName, char *filename) val, _DtACTION_TTN_ARG, "n", _DtACTION_TTN_REP_TYPE); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); - if ( val ) free(val); - if (buf) free(buf); + free(val); + free(buf); return NULL; } break; @@ -1038,7 +1038,7 @@ _DtActionConverter(DtDtsDbField * fields, (void) sprintf (buf, noFields, fields[0].fieldValue, fileName); _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); XtFree(fileName); - if (buf) XtFree(buf); + XtFree(buf); _DtSvcProcessUnlock(); return(True); } @@ -1128,7 +1128,7 @@ _DtActionConverter(DtDtsDbField * fields, * code which follows the continue statement. *************************************************/ _DtSimpleError(DtProgName,DtWarning, NULL, "%s", buf); - if (buf) XtFree(buf); + XtFree(buf); continue; } @@ -1156,7 +1156,7 @@ _DtActionConverter(DtDtsDbField * fields, _DtSimpleError(DtProgName,DtError, NULL, "%s", buf); _DtDtsDbDeleteRecord(act_rec,act_db); XtFree(fileName); - if (buf) XtFree(buf); + XtFree(buf); free(fieldVal); _DtSvcProcessUnlock(); return True; diff --git a/cde/lib/DtSvc/DtUtil1/DbReader.c b/cde/lib/DtSvc/DtUtil1/DbReader.c index ea31e001..e7c03cc4 100644 --- a/cde/lib/DtSvc/DtUtil1/DbReader.c +++ b/cde/lib/DtSvc/DtUtil1/DbReader.c @@ -1034,7 +1034,7 @@ ReadNextEntry( sprintf(error_buffer, invalidVersion, file_name); _DtSimpleError(DtProgName, DtError, NULL, "%s", error_buffer); XtFree(version); - if (error_buffer) XtFree(error_buffer); + XtFree(error_buffer); return(False); } @@ -1107,7 +1107,7 @@ ReadNextEntry( (void) sprintf (error_buffer, incompleteDefn, errorName, file_name); _DtSimpleError (DtProgName, DtError, NULL, "%s", error_buffer); - if (error_buffer) XtFree(error_buffer); + XtFree(error_buffer); remove_defn = True; } break; @@ -1167,7 +1167,7 @@ ReadNextEntry( (void) sprintf (error_buffer, invalidStartSymbol, errorName, file_name); _DtSimpleError (DtProgName, DtError, NULL, "%s", error_buffer); - if (error_buffer) XtFree(error_buffer); + XtFree(error_buffer); remove_defn = True; break; } @@ -1186,7 +1186,7 @@ ReadNextEntry( (void) sprintf (error_buffer, missingStartSymbol, errorName, file_name); _DtSimpleError (DtProgName, DtError, NULL, "%s", error_buffer); - if (error_buffer) XtFree(error_buffer); + XtFree(error_buffer); remove_defn = True; break; } @@ -1203,7 +1203,7 @@ ReadNextEntry( (void) sprintf (error_buffer, multiLineDefn, errorName, file_name); _DtSimpleError (DtProgName, DtError, NULL, "%s", error_buffer); - if (error_buffer) XtFree(error_buffer); + XtFree(error_buffer); remove_defn = True; } /* if '}' end found with no starting '{', ignore defn */ @@ -1216,7 +1216,7 @@ ReadNextEntry( (void) sprintf (error_buffer, noStartSymbol, errorName, file_name); _DtSimpleError (DtProgName, DtError, NULL, "%s", error_buffer); - if (error_buffer) XtFree(error_buffer); + XtFree(error_buffer); remove_defn = True; } break; @@ -1239,7 +1239,7 @@ ReadNextEntry( XrmQuarkToString ((*fieldPtr)[0].fieldName); (void)sprintf (error_buffer, tooManyFields, errorName, file_name); _DtSimpleError (DtProgName, DtError, NULL, "%s", error_buffer); - if (error_buffer) XtFree(error_buffer); + XtFree(error_buffer); remove_defn = True; break; } @@ -1336,8 +1336,7 @@ ReadNextEntry( { for (i = 0; i < indx; i++) { - if ((*fieldPtr)[i].fieldValue) - XtFree ((char *) (*fieldPtr)[i].fieldValue); + XtFree ((char *) (*fieldPtr)[i].fieldValue); } } else @@ -1631,7 +1630,7 @@ DefineVariable( errorBuffer = XtMalloc(MAXPATHLEN); sprintf(errorBuffer, cantSetVersion, fileName); _DtSimpleError(DtProgName, DtError, NULL, "%s", errorBuffer); - if (errorBuffer) XtFree(errorBuffer); + XtFree(errorBuffer); return(False); } } @@ -1827,8 +1826,7 @@ FreeDbField( while (fields[i].fieldName || fields[i].fieldValue) { - if (fields[i].fieldValue) - XtFree(fields[i].fieldValue); + XtFree(fields[i].fieldValue); i++; } diff --git a/cde/lib/DtSvc/DtUtil1/Dts.c b/cde/lib/DtSvc/DtUtil1/Dts.c index 4bd1bbe0..1471a6d1 100644 --- a/cde/lib/DtSvc/DtUtil1/Dts.c +++ b/cde/lib/DtSvc/DtUtil1/Dts.c @@ -1062,8 +1062,8 @@ _DtDtsGetDataType(const char *file) } close(fd); } - if(buff)free(buff); - if(name)free(name); + free(buff); + free(name); return(dt); } @@ -1566,7 +1566,7 @@ expand_keyword(const char *attr_in, const char *in_pathname) continue; } } - if(netPath)free(netPath); + free(netPath); return(buf); } else @@ -1635,8 +1635,8 @@ expand_shell(const char *attr) _DtSimpleError( DtProgName, DtError, NULL, (char*) &start[1], NULL); - if(nattr)free(nattr); - if(results)free(results); + free(nattr); + free(results); return(NULL); } @@ -1650,7 +1650,7 @@ expand_shell(const char *attr) srch = end+1; } results = append(results, srch); - if(nattr) free(nattr); + free(nattr); return(results); } @@ -1773,9 +1773,9 @@ DtDtsFreeAttributeList(DtDtsAttribute **list) { while(list[i] && list[i]->name) { - if(list[i]->name)free(list[i]->name); - if(list[i]->value)free(list[i]->value); - if(list[i]) free(list[i]); + free(list[i]->name); + free(list[i]->value); + free(list[i]); i++; } free(list); @@ -1825,13 +1825,13 @@ DtDtsBufferToAttributeValue(const void *buffer, const int size, const char *attr void DtDtsFreeAttributeValue(char *value) { - if(value) free(value); + free(value); } void DtDtsFreeDataType(char *datatype) { - if(datatype) free(datatype); + free(datatype); } int diff --git a/cde/lib/DtSvc/DtUtil1/DtsDb.c b/cde/lib/DtSvc/DtUtil1/DtsDb.c index 4bccbfb5..156f54e5 100644 --- a/cde/lib/DtSvc/DtUtil1/DtsDb.c +++ b/cde/lib/DtSvc/DtUtil1/DtsDb.c @@ -255,8 +255,8 @@ _DtDtsDbDeleteDb(DtDtsDbDatabase *db) _DtSvcProcessLock(); _DtDtsDbDeleteRecords(db); - if(db->databaseName) free(db->databaseName); - if(db) free(db); + free(db->databaseName); + free(db); for(i = 0; db_list[i]; i++) { @@ -272,7 +272,7 @@ _DtDtsDbDeleteDb(DtDtsDbDatabase *db) } if(db_list[0] == 0) { - if(db_list)free(db_list); + free(db_list); db_list = 0; } _DtSvcProcessUnlock(); @@ -439,7 +439,7 @@ _DtDtsDbAddRecord(DtDtsDbDatabase *db) { memmove(newlist, db->recordList, rec*sizeof(DtDtsDbRecord *)); - if(db->recordList) free(db->recordList); + free(db->recordList); } db->recordList = newlist; } @@ -455,7 +455,7 @@ _DtDtsDbDeleteRecord(DtDtsDbRecord *rec, DtDtsDbDatabase *db) int i; _DtDtsDbDeleteFields(rec); - if(rec) free(rec); + free(rec); for(i = 0; i < db->recordCount; i++) { @@ -481,11 +481,9 @@ _DtDtsDbDeleteRecords(DtDtsDbDatabase *db) for(i = 0; i < db->recordCount; i++) { _DtDtsDbDeleteFields(db->recordList[i]); - if(db->recordList[i]) - free(db->recordList[i]); + free(db->recordList[i]); } - if(db->recordList) - free(db->recordList); + free(db->recordList); db->recordList = 0; return(0); } @@ -504,8 +502,7 @@ _DtDtsDbAddField(DtDtsDbRecord *rec) { memmove(newlist, rec->fieldList, flds*sizeof(DtDtsDbField *)); - if(rec->fieldList) - free(rec->fieldList); + free(rec->fieldList); } rec->fieldList = newlist; } @@ -520,7 +517,7 @@ _DtDtsDbDeleteField(DtDtsDbField *fld, DtDtsDbRecord *rec) { int i; - if(fld) free(fld); + free(fld); for(i = 0; i < rec->fieldCount; i++) { if(rec->fieldList[i] == fld) @@ -544,12 +541,10 @@ _DtDtsDbDeleteFields(DtDtsDbRecord *rec) for(i = 0; i < rec->fieldCount; i++) { - if(rec->fieldList[i]->fieldValue) - free(rec->fieldList[i]->fieldValue); - if(rec->fieldList[i]) - free(rec->fieldList[i]); + free(rec->fieldList[i]->fieldValue); + free(rec->fieldList[i]); } - if(rec->fieldList) free(rec->fieldList); + free(rec->fieldList); rec->fieldList = 0; return(0); } diff --git a/cde/lib/DtSvc/DtUtil1/MMDb.c b/cde/lib/DtSvc/DtUtil1/MMDb.c index 2bb058f5..b06605ae 100644 --- a/cde/lib/DtSvc/DtUtil1/MMDb.c +++ b/cde/lib/DtSvc/DtUtil1/MMDb.c @@ -176,7 +176,7 @@ build_file_list(DtShmProtoIntList int_handle, DtDirPaths *dirs, mtime_list[count-1] = buf.st_mtime; boson_list[count-1] = _DtShmProtoAddStrtab(shm_handle, pathname, &isnew); - if (pathname) free(pathname); + free(pathname); continue; } } @@ -188,8 +188,8 @@ build_file_list(DtShmProtoIntList int_handle, DtDirPaths *dirs, data = _DtShmProtoAddIntLst(int_handle, count*sizeof(time_t)/sizeof(int), &header->mtimes_offset); memcpy(data, mtime_list, count*sizeof(time_t)); header->files_count = count; - if(boson_list)free(boson_list); - if(mtime_list)free(mtime_list); + free(boson_list); + free(mtime_list); return; } @@ -662,9 +662,9 @@ printf("head->buffer_start_index = %d\n", head->buffer_start_index); &head->name_list_offset); _DtShmProtoCopyInttab(indexList, space); _DtShmProtoDestroyInttab(indexList); - if(name_index)free(name_index); - if(list_of_recs)free(list_of_recs); - if(other)free(other); + free(name_index); + free(list_of_recs); + free(other); return(index); } diff --git a/cde/lib/DtSvc/DtUtil2/ChkpntClient.c b/cde/lib/DtSvc/DtUtil2/ChkpntClient.c index c0ea1d4f..45e33f5a 100644 --- a/cde/lib/DtSvc/DtUtil2/ChkpntClient.c +++ b/cde/lib/DtSvc/DtUtil2/ChkpntClient.c @@ -275,7 +275,7 @@ _DtPerfChkpntInit(Display *display, XStringListToTextProperty(array, 1, &text_prop); XSetWMName(tmpdisplay, dtcp_info.window, &text_prop); XFree(text_prop.value); - if (buffer) free(buffer); + free(buffer); } XCloseDisplay(tmpdisplay); diff --git a/cde/lib/DtSvc/DtUtil2/EnvControl.c b/cde/lib/DtSvc/DtUtil2/EnvControl.c index e6508939..ef65f04c 100644 --- a/cde/lib/DtSvc/DtUtil2/EnvControl.c +++ b/cde/lib/DtSvc/DtUtil2/EnvControl.c @@ -934,8 +934,7 @@ _DtEnvRemove( rather than try to do it ourselves. */ - if (str) - unsetenv(str); + unsetenv(str); #else freeMe = pEnviron2[index]; @@ -1021,11 +1020,11 @@ _AddToPath ( if (sPath != NULL) { - sNew = XtRealloc (sPath, 1+strlen(sPath)+1+strlen(sDir)); + sNew = XtRealloc (sPath, strlen(sPath) + 1 + strlen(sDir) + 1); } else { - sNew = XtMalloc (1+strlen(sPath)+1+strlen(sDir)); + sNew = XtMalloc (1 + strlen(sDir) + 1); } strcat (sNew, ":"); @@ -1187,7 +1186,7 @@ _DtWsmSetBackdropSearchPath ( if (postDtEnvironmentString != postDtEnvironmentStringBuf) { - if (postDtEnvironmentString) XtFree(postDtEnvironmentString); + XtFree(postDtEnvironmentString); postDtEnvironmentString = NULL; }