Showing results for 
Search instead for 
Do you mean 
Reply

Segmentation fault in ITK

[ Edited ]

Hi,

 

I'm getting segmentation fault in the following function.

  

//parse the input file whcih contains the attribute values and perform some checks
while (fgets( currentLineStr, 400, inputFile ) != NULL )
{
++countS;
tempStr = strsplit(currentLineStr, "|", &numtokens);
if(countS==1)
{
if(numheadtokens!=numtokens)
{
fprintf(logFile, "There is a mismatch in the no: of pipe counts in input.csv and head.txt. Please correct and rerun.\n");
if(inputFile)
fclose(inputFile);
if(errorFile)
fclose(errorFile);
if(logFile)
fclose(logFile);
if(outFile)
fclose(outFile);
if(existingPartFile)
fclose(existingPartFile);
if(nonExistingPartFile)
fclose(nonExistingPartFile);
if(headFile)
fclose(headFile);
exit(EXIT_FAILURE);
}
}
fprintf(logFile, "Line %d: %s\n", countS, currentLineStr);
flag=0;
printf("\nHi1\n");
for (i = 0; i < numtokens; i++)
{
if(i==1)
{
printf("\nHHH");
strcpy(itemId,tempStr[i]);
attribValues[0]=itemId;
fprintf(existingPartFile, "%s\n", itemId);
attribNames[0]=(char *)MEM_alloc( strlen( "item_id" ) + 1 );
attribNames[0]="item_id";
ifail = ITEM_find_items_by_key_attributes(count,attribNames,attribValues,&noOfItems,&objects);
if (noOfItems == 0)
{
fprintf(errorFile, "The part %s does not exist\n", itemId);
fprintf(logFile, "Line %dSmiley Tongueart Number %s does not exist\n", countS, itemId);
fprintf(nonExistingPartFile, "%s\n", itemId);
printf("\nThe part %s does not exist", itemId);
flag=1;
}
else
{
ifail = ICS_ask_classification_object(objects[0],&classObjs);
if (classObjs!=NULLTAG)
{
fprintf(errorFile, "The classification already exist for item:%s in TeamCenter \n", itemId);
printf("\n Classification already exists for item:%s \n",itemId);
flag=1;
}
}
noOfItems=0;
if (objects) MEM_free(objects);
}
else if(i==2)
{
printf("\n SIta1");
classCount=0;
sprintf(classNameStr, "-607 = %s", tempStr[i]);
tempclassStr=(char *)malloc(strlen(classNameStr) *sizeof(char)+1 );
if(tempclassStr)
{
strcpy(tempclassStr,classNameStr);
ifail = ICS_class_search(tempclassStr, -607, &classCount, NULL,NULL,&classIdStr,NULL,NULL,NULL,NULL,NULL);
}
if(tempclassStr)//added for freeing
{
free(tempclassStr);
tempclassStr=NULL;
}
printf("\n SIta100");
if(classCount>0)
{
printf("\n SIta101");
tempLineStr = str_replace(currentLineStr,tempStr[i],classIdStr[0]);
classId=(char *)malloc(strlen(classIdStr[0]) *sizeof(char)+1 );
if(classId)
{
strcpy(classId,classIdStr[0]);
}
printf("\n SIta103");
}
else{
printf("\n SIta102");
fprintf(errorFile, "The class %s does not exist\n", tempStr[i]);
fprintf(logFile, "Line %d:Class %s does not exist\n", countS, tempStr[i]);
if(inputFile)
fclose(inputFile);
if(errorFile)
fclose(errorFile);
if(logFile)
fclose(logFile);
if(outFile)
fclose(outFile);
if(existingPartFile)
fclose(existingPartFile);
if(nonExistingPartFile)
fclose(nonExistingPartFile);
if(headFile)
fclose(headFile);
exit(EXIT_FAILURE);
}

}
else if(i==7){
printf("\n SIta2");
//newcurrentLineStr= str_append(tempLineStr,classAttribId); //prefix with attribute id for each of the attribute value
printf("Line %d",countS);

}
if(i>=7)
{
ifail= ICS_class_ask_attr_property(classId,classAttribId[i],"_FORMAT",&keyLovStr);
if(classId)
{
free(classId);
classId=NULL;
}

if(keyLovStr)
{
printf("\n SIta3");
printf("\n keyLovVlaue:%s",keyLovStr);
ifail=ICS_keylov_ask_tag(keyLovStr,&lovTag);

MEM_free(keyLovStr);
keyLovStr=NULL;
}
keyLovFlag=0;
printf("\n SIta4");
}
if(classIdStr)
{
MEM_free(classIdStr);
classIdStr=NULL;
}

}
printf("\n SIta5");
if(lovCount>0)
{
printf("\nSita3 %d ",numtokens);


}
lovCount=0;
for(j=0;j<numtokens; j++) //added for freeing
{
if(tempStr[j])
free(tempStr[j]);
tempStr[j]=NULL;
}
printf("\n SIta8");
if(flag!=1)
{
printf("\n SIta6");
fprintf(logFile, "New Line %d: %s\n", countS, newcurrentLineStr);
fprintf(outFile, "%s\n", newcurrentLineStr);
}
/*
if(newcurrentLineStr)
{
free(newcurrentLineStr);
newcurrentLineStr=NULL;
}*/
}
printf("\n SIta7");
if(inputFile)
fclose(inputFile);
if(errorFile)
fclose(errorFile);
if(logFile)
fclose(logFile);
if(outFile)
fclose(outFile);
if(existingPartFile)
fclose(existingPartFile);
if(nonExistingPartFile)
fclose(nonExistingPartFile);
}

 

I'm getting the following output

 

 

infodba@tcuaapq1 tcdata$ ./partsearch -u=infodba -p=<password> -g=dba

 

login to database successful.

 

Hi

 

Hi1

 

HHH

 SIta1

 SIta100

 SIta101

 SIta103

 SIta2Line 1

 SIta3

Segmentation fault

You have new mail in /var/spool/mail/infodba