malloc のないシリーズを探しています。何千ものテストケースがあるとします。人々は ptr を解放するのを忘れるかもしれません。スクリプトの最適化を手伝ってください。
テスト中のサンプルファイル
Test(func_class,func1)
{
int i,j;
char* ptr = (char*) malloc(sizeof(char));
free(ptr);
}
Test(func_class,func1)
{
int i,j;
char* ptr = (char*) malloc(sizeof(char));
/ Memory Leak /
}
開発中のスクリプト:
export MY_ROOT=`pwd`
_COUNT=0
pwd
_COUNT_WORD=0
filename=test.c
cat $filename | while read line
do
echo "Reading Line = $LINE"
for word in $line
do
_COUNT_WORD=$(($_COUNT_WORD+1))
echo $_COUNT_WORD $word
if [ "$word" == "malloc\(sizeof\(char\)\);" ]; then
_MALLOC_FLAG=1 #this part of the code is not reached
echo "Malloc Flag Hi"
echo $word[2]
fi
done
_COUNT_WORD=0
done
malloc regex のマッチングに問題があります。malloc を記述する個々のユーザーのパターンを見つける必要があるため、スクリプトに多くの変更が必要であることはわかっています。