• R/O
  • HTTP
  • SSH
  • HTTPS

xkeymacs: Commit


Commit MetaInfo

Revisión6c5924fd837243d5ae4a18873e42d6b50bc1e8ae (tree)
Tiempo2014-09-20 20:38:11
AutorKazuhiro Fujieda <fujieda@user...>
CommiterKazuhiro Fujieda

Log Message

Make some modifications to TSFHandler

- Remove unnecessary activation of TSF
- Fix a possible null dereference
- Uninstall an installed advice sink to avoid a resource leak

Cambiar Resumen

Diferencia incremental

--- a/xkeymacsdll/TSFHandler.cpp
+++ b/xkeymacsdll/TSFHandler.cpp
@@ -15,17 +15,15 @@ TSFHandler::TSFHandler()
1515 {
1616 m_RefCount = 1;
1717 m_ThreadMgr = nullptr;
18- m_ClientId = 0;
18+ m_Cookie = TF_INVALID_COOKIE;
1919 m_Context = nullptr;
2020 m_CompositionState = false;
2121 }
2222
2323 TSFHandler::~TSFHandler()
2424 {
25- if (m_ThreadMgr) {
26- m_ThreadMgr->Deactivate();
25+ if (m_ThreadMgr)
2726 m_ThreadMgr->Release();
28- }
2927 if (m_Context)
3028 m_Context->Release();
3129 }
@@ -50,16 +48,13 @@ void TSFHandler::InitSink()
5048 return;
5149 }
5250 tsfh->m_ThreadMgr = thread;
53- if (FAILED(thread->Activate(&tsfh->m_ClientId))) {
54- DebugLog(_T("ThreadMgr->Activate failed."));
55- goto fail;
56- }
5751 ITfSource *src;
5852 if (FAILED(thread->QueryInterface(&src))) {
5953 DebugLog(_T("ThreadMgr->QueryInterface failed."));
6054 goto fail;
6155 }
62- if (FAILED(src->AdviseSink(IID_ITfThreadMgrEventSink, static_cast<ITfThreadMgrEventSink *>(tsfh), &tsfh->m_ClientId))) {
56+ DWORD cookie;
57+ if (FAILED(src->AdviseSink(IID_ITfThreadMgrEventSink, static_cast<ITfThreadMgrEventSink *>(tsfh), &cookie))) {
6358 DebugLog(_T("Souece->AdviseSink failed."));
6459 src->Release();
6560 goto fail;
@@ -122,20 +117,37 @@ STDMETHODIMP TSFHandler::OnSetFocus(ITfDocumentMgr *docMgr, ITfDocumentMgr *)
122117 DebugLog(_T("OnSetFocus"));
123118 if (docMgr == nullptr)
124119 return S_OK;
120+ if (m_Cookie != TF_INVALID_COOKIE) {
121+ ITfSource *src;
122+ if (FAILED(m_Context->QueryInterface(&src))) {
123+ DebugLog(_T("Context->QueryInterface:0 failed."));
124+ return S_OK;
125+ }
126+ HRESULT hr = src->UnadviseSink(m_Cookie);
127+ src->Release();
128+ if (FAILED(hr)) {
129+ DebugLog(_T("Source->UnadviceThink failed."));
130+ return S_OK;
131+ }
132+ m_Context->Release();
133+ m_Context = nullptr;
134+ m_Cookie = TF_INVALID_COOKIE;
135+ }
125136 ITfContext *cxt;
126137 if (FAILED(docMgr->GetTop(&cxt))) {
127138 DebugLog(_T("DocumentMgr->GetTop failed."));
128139 return S_OK;
129140 }
130- if (m_Context == cxt)
131- goto fail;
132- ITfSource *src = nullptr;
141+ if (cxt == nullptr) {
142+ DebugLog(_T("ITfContext is null."));
143+ return S_OK;
144+ }
145+ ITfSource *src;
133146 if (FAILED(cxt->QueryInterface(&src))) {
134- DebugLog(_T("Context->QueryInterface(ITfSource) failed."));
147+ DebugLog(_T("Context->QueryInterface:1 failed."));
135148 goto fail;
136149 }
137- DWORD cookie;
138- if (FAILED(src->AdviseSink(IID_ITfTextEditSink, static_cast<ITfTextEditSink *>(this), &cookie))) {
150+ if (FAILED(src->AdviseSink(IID_ITfTextEditSink, static_cast<ITfTextEditSink *>(this), &m_Cookie))) {
139151 DebugLog(_T("Source->AdviseSink(ITfTextEditSink) failed."));
140152 src->Release();
141153 goto fail;
--- a/xkeymacsdll/TSFHandler.h
+++ b/xkeymacsdll/TSFHandler.h
@@ -28,7 +28,7 @@ public:
2828 private:
2929 ULONG m_RefCount;
3030 ITfThreadMgr *m_ThreadMgr;
31- TfClientId m_ClientId;
31+ DWORD m_Cookie;
3232 ITfContext *m_Context;
3333 bool m_CompositionState;
3434 };
Show on old repository browser