내 gtkSourceView에서 콜백 "query-tooltip-text"를 사용하고 싶습니다. 내가 사용하여 신호에 대한 콜백을 연결 :이 툴팁을 표시 할 필요가있는 때마다, 내 메소드가 불려 .. 잘 작동gtkSourceView - query-tooltip-text 사용
...
g_signal_connect(G_OBJECT(attributes), "query-tooltip-text", G_CALLBACK(on_lineMarkerTooltip_displayed), context->plainTextEditor_lineMarkers[lineNumber-1]->message);
. ...->message
은 영구적으로 메모리에있는 C 문자열입니다. 여기 내 콜백 메소드 : 완료되면
gchar* on_lineMarkerTooltip_displayed(GtkSourceMarkAttributes *attributes, GtkSourceMark *mark, char* message)
{
printf("message3: %s\n", message); // just to see what is going on
return message;
}
내가 문자열과 자유의 수명을 제어해야하는 gtk3 source doc 통계는, 내가 그 괜찮을한다고 생각합니다.
이 두 번째로 호출 된 후 내 콜백 이중 무료 segfault의 실패 그러나 :
...
message3: bad hour
message3:
message3: `�/EV
*** Error in `./cron-gui': double free or corruption (fasttop): 0x000056452fc70240 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bcb)[0x7f85670a9bcb]
/lib/x86_64-linux-gnu/libc.so.6(+0x76f96)[0x7f85670aff96]
/lib/x86_64-linux-gnu/libc.so.6(+0x7778e)[0x7f85670b078e]
/usr/lib/x86_64-linux-gnu/libgtk-3.so.0(+0x214447)[0x7f85694
...
공식 문서에 말보다 그래서 다른
, 그것은 gtk3처럼 보이는 는 사용 후 문자열의 메모리를 해제 . 나는 그렇게 따라 내 콜백을 수정하려고 : 잘 작동
gchar* on_lineMarkerTooltip_displayed(GtkSourceMarkAttributes *attributes, GtkSourceMark *mark, char* message)
{
printf("message3: %s\n", message); // just to see what is going on
return strdup(message);
}
그러나 나는 내 응용 프로그램은 이제 메모리를 먹을 수 있다고 우려하고있다. query-tooltip-text
콜백의 올바른 사용법을 알고 있습니까?