SF 3435567

Possibility to pass a NULL Dispatch pointer
Fix a memory leak (detected with Glowcode) in Variant.cpp/zeroVariant function
Variant.toString improvement to handle NULL cases
Adds the error code to the message when "an unknown COM error has occurred"
Added debug info to EventProxy advise registration failure message.
This commit is contained in:
clay_shooter
2011-12-11 16:57:28 +00:00
parent e5652e3b75
commit 1e69bb9acb
6 changed files with 61 additions and 5 deletions

View File

@@ -342,8 +342,15 @@ static wchar_t* CreateErrorMsgFromResult(HRESULT inResult)
msg = (wchar_t*) ::LocalAlloc(LPTR, bufferLength);
wcscpy_s(msg, bufferLength, message_text);
}
// SF 3435567 add HRESULT to error message
size_t bufferLength = (wcslen(msg) + 100) * sizeof(wchar_t);
wchar_t* plus = (wchar_t*) ::LocalAlloc(LPTR, bufferLength);
// Had to force this to wide/unicode. We must be missing a macro or setting somewhere
wsprintfW(plus, L"%x / %s", inResult, msg);
return msg;
::LocalFree(msg);
return plus;
}
static wchar_t* CreateErrorMsgFromInfo(HRESULT inResult, EXCEPINFO* ioInfo,

View File

@@ -50,7 +50,10 @@ void EventProxy::Connect(JNIEnv *env) {
connected = 1;
} else {
connected = 0;
ThrowComFail(env, "Advise failed", hr);
// SF 3435567 added debug info to advise failed message
char tmp[256];
sprintf_s( tmp, 256, "Advise failed with %x (CONNECT_E_ADVISELIMIT is %x)", (int)hr, (int)(CONNECT_E_ADVISELIMIT) );
ThrowComFail(env, tmp, hr);
}
}
@@ -240,6 +243,7 @@ STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
VARIANT *com = &pDispParams->rgvarg[i];
convertJavaVariant(java, com);
// SF 1689061 change not accepted but put in as comment for later reminder
// note that a related fix has been submitted in SF 3435567 to do this in zeroVariant() method
//Java_com_jacob_com_Variant_release(env, arg);
zeroVariant(env, arg);
env->DeleteLocalRef(arg);

View File

@@ -95,6 +95,12 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_init
*/
void zeroVariant(JNIEnv *env, jobject _this)
{
// sf 3435567 Fix a memory leak (detected with Glowcode) in Variant.cpp/zeroVariant function
// does this code conflict with the function/method documentation now?
// note that a related fix was proposed in SF 1689061 in EventProxy.cpp but never accepted
VARIANT *v = extractVariant(env, _this);
delete v;
jclass clazz = env->GetObjectClass(_this);
jfieldID jf = env->GetFieldID(clazz, VARIANT_FLD, "I");
env->SetIntField(_this, jf, (unsigned int)0);
@@ -632,12 +638,14 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDispatch
{
VARIANT *v = extractVariant(env, _this);
IDispatch *disp = extractDispatch(env, _that);
if (disp && v) {
if (v) {
VariantClear(v); // whatever was there before
V_VT(v) = VT_DISPATCH;
V_DISPATCH(v) = disp;
// I am handing the pointer to COM
disp->AddRef();
// SF 3435567 support null dispatch pointer
if( disp )
disp->AddRef();
} else ThrowComFail(env, "putObject failed", -1);
}