2012-08-30 68 views
7

我寫了一個web服務客戶端與gSoap和使用Valgrind檢查內存問題。gsoap/valgrind;沒有泄漏,但內存錯誤

Valgrind的報告沒有泄漏,但顯示了這個奇怪的(至少對我來說)內存錯誤信息:

==3529== Conditional jump or move depends on uninitialised value(s) 
==3529== at 0x405D6DC: soap_reference (stdsoap2.c:6926) 
==3529== by 0x405305D: soap_serialize_string (sepomexC.c:4982) 
==3529== by 0x404AF5E: soap_serialize_ns1__asentamientosPorCodigoPostalRqType (sepomexC.c:2629) 
==3529== by 0x40500F3: soap_serialize_PointerTons1__asentamientosPorCodigoPostalRqType (sepomexC.c:4103) 
==3529== by 0x4046666: soap_serialize___sep__consultarAsentamientosPorCodigoPostal (sepomexC.c:1233) 
==3529== by 0x4053A7D: soap_call___sep__consultarAsentamientosPorCodigoPostal (sepomexClient.c:186) 
==3529== by 0x40417CA: consultarAsentamientosPorCodigoPostal (main.c:73) 
==3529== by 0x804870C: main (sepomexmain.c:31) 
==3529== 
==3529== Conditional jump or move depends on uninitialised value(s) 
==3529== at 0x4061AA5: soap_element_id (stdsoap2.c:9583) 
==3529== by 0x4068B0C: soap_outstring (stdsoap2.c:12681) 
==3529== by 0x4052DAE: soap_out_xsd__integer (sepomexC.c:4918) 
==3529== by 0x404B062: soap_out_ns1__asentamientosPorCodigoPostalRqType (sepomexC.c:2643) 
==3529== by 0x4050179: soap_out_PointerTons1__asentamientosPorCodigoPostalRqType (sepomexC.c:4111) 
==3529== by 0x4046698: soap_out___sep__consultarAsentamientosPorCodigoPostal (sepomexC.c:1238) 
==3529== by 0x4046818: soap_put___sep__consultarAsentamientosPorCodigoPostal (sepomexC.c:1274) 
==3529== by 0x4053AF6: soap_call___sep__consultarAsentamientosPorCodigoPostal (sepomexClient.c:193) 
==3529== by 0x40417CA: consultarAsentamientosPorCodigoPostal (main.c:73) 
==3529== by 0x804870C: main (sepomexmain.c:31) 

==3529== 
==3529== HEAP SUMMARY: 
==3529==  in use at exit: 0 bytes in 0 blocks 
==3529== total heap usage: 160 allocs, 160 frees, 16,161 bytes allocated 
==3529== 
==3529== All heap blocks were freed -- no leaks are possible 
==3529== 
==3529== For counts of detected and suppressed errors, rerun with: -v 
==3529== Use --track-origins=yes to see where uninitialised values come from 
==3529== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 21 from 8) 

的無泄漏是個好消息,但此錯誤很重要?據我所知,它們是在stdsoap2.c(一個gSoap文件)中生成的。

謝謝。

編輯:謝謝你的回答。正如你們中的一些人告訴我的,我有未初始化的東西,這是我的請求結構變量。我這樣修復:

struct ns1__myRequestType request; 
memset(&request, 0, sizeof(struct ns1__myRequestType)); 

現在Valgrind的輸出是「乾淨」:)非常感謝。

+0

你可以發佈你的'main()'的代碼嗎? – hmjd

+2

是的,它們通常非常重要,這可能是因爲你的代碼將未初始化的東西傳入gSoap庫。 – nos

回答

3

它基本上是指根據未初始化的變量取得一些分支的事實。它們可以簡單地作爲在庫函數範圍內的局部範圍內的自動變量,它們在堆棧中分配,並且在if,while,switch或其他形式的分支表達式中使用它們之前未被賦值。一般來說,這不是一件好事,因爲它可能導致未定義的行爲,但是如果錯誤在庫的內部,編寫者可能正在進行某種類型的假定的內存覆蓋操作等等,這些變量使得他們非正式地「初始化」而不是用標準C語法明確初始化。另一種可能性是你也可能會將指向未初始化變量的指針傳遞給庫函數之一,這將是糟糕的編程形式,並可能產生不可預知的結果或安全風險。