Wireshark ディセクタを作成していて、奇妙なメモリ管理の問題が発生しています。私は次の機能を持っています:
guint8* foo_hex2bytes(guchar *str, guint len){
...
//allocate memory for the result and start converting
res = (guint8*)wmem_alloc(scope, sizeof(guint8)*((len>>1)));
for(i=0; i<(len>>1); i++){
//check that the two digits under question are HEX digits
if(!isxdigit(*(str+2*i)) || !isxdigit(*(str+2*i+1))){
wmem_free(scope, res);
return NULL;
}
//append the byte
sscanf((const char*)(str+2*i), "%02x", &res[i]);
}
return res;
}
この関数はいくつかの場所 (proto_reg_hanoff_foo
およびdissect_foo
) で使用されるため、結果を特定のプールに割り当てません。
私 proto_reg_handoff_foo
は関数の戻り値を取得し、それを別のメモリ位置にコピーし、元の結果を解放しています:
...
if(syskey_str && strlen(syskey_str)){
wmem_free(wmem_epan_scope(), syskey_bytes);
if(tmp = foo_hex2bytes((guchar*)syskey_str, (guint) strlen(syskey_str))){
syskey_len = (guint)strlen(syskey_str)>>1;
syskey_bytes = (guint8*)wmem_alloc(wmem_epan_scope(), strlen(syskey_str)>>1);
memcpy(syskey_bytes, tmp, strlen(syskey_str)>>1);
wmem_free(NULL, tmp);
}
}
...
奇妙なことに、行で Windows によってトリガーされるブレークポイント (またはデバッガーの外部での単純なクラッシュ) を取得していますwmem_free(NULL, tmp)
。でエラーが発生したという事実以外に、収集できる実際のデバッグ情報はありませんwmem_core.c:72
。
注意: 3 番目のパラメーターfoo_hex2bytes
を受け入れるように my を変更し、単純に(または必要に応じて) 渡しました。これにより、アプリケーションが閉じられているときに同様のクラッシュが発生します。また、すべてのメモリを使用して手動でクリアしようとしました(アプリケーションが14Kのメモリしか使用せず、さらに多くのメモリを使用できる場合でも、動作する場合があります)。wmem_allocator_t
wmem_epan_scope()
wmem_packet_scope()
malloc()
null pointer
編集:問題は並んでいるようですsscanf(...)
-十分なメモリを割り当てておらず、オーバーランしていました。割り当てサイズを増やすことで修正されました。