1224219 added unicode support to SafeArray.fromStringArray. Closed memory leak in SafeArray.getString
This commit is contained in:
@@ -52,6 +52,14 @@
|
|||||||
<td width="87%">Removed Variant serializable interface because it is not
|
<td width="87%">Removed Variant serializable interface because it is not
|
||||||
actually serializable on 2000/xp(pre1)</td>
|
actually serializable on 2000/xp(pre1)</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="13%">1224219</td>
|
||||||
|
<td width="87%">Memory leak in SafeArray.GetString()(pre3)</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td width="13%">1224219</td>
|
||||||
|
<td width="87%">Change from UTF to UNICODE SafeArray.fromStringArray()(pre3)</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td width="13%"> </td>
|
<td width="13%"> </td>
|
||||||
<td width="87%"> </td>
|
<td width="87%"> </td>
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_QueryInterface
|
|||||||
// get the current IDispatch
|
// get the current IDispatch
|
||||||
IDispatch *pIDispatch = extractDispatch(env, _this);
|
IDispatch *pIDispatch = extractDispatch(env, _this);
|
||||||
if (!pIDispatch) return NULL;
|
if (!pIDispatch) return NULL;
|
||||||
|
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||||
const char *siid = env->GetStringUTFChars(_iid, NULL);
|
const char *siid = env->GetStringUTFChars(_iid, NULL);
|
||||||
USES_CONVERSION;
|
USES_CONVERSION;
|
||||||
LPOLESTR bsIID = A2W(siid);
|
LPOLESTR bsIID = A2W(siid);
|
||||||
@@ -95,6 +96,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstanceNative
|
|||||||
jclass clazz = env->GetObjectClass(_this);
|
jclass clazz = env->GetObjectClass(_this);
|
||||||
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
||||||
|
|
||||||
|
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||||
CLSID clsid;
|
CLSID clsid;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
@@ -161,6 +163,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstanceNative
|
|||||||
jclass clazz = env->GetObjectClass(_this);
|
jclass clazz = env->GetObjectClass(_this);
|
||||||
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
||||||
|
|
||||||
|
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||||
CLSID clsid;
|
CLSID clsid;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
@@ -203,6 +206,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_coCreateInstanceNative
|
|||||||
jclass clazz = env->GetObjectClass(_this);
|
jclass clazz = env->GetObjectClass(_this);
|
||||||
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
||||||
|
|
||||||
|
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||||
CLSID clsid;
|
CLSID clsid;
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
@@ -275,6 +279,7 @@ JNIEXPORT jintArray JNICALL Java_com_jacob_com_Dispatch_getIDsOfNames
|
|||||||
{
|
{
|
||||||
USES_CONVERSION;
|
USES_CONVERSION;
|
||||||
jstring s = (jstring)env->GetObjectArrayElement(names, i);
|
jstring s = (jstring)env->GetObjectArrayElement(names, i);
|
||||||
|
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||||
const char *nm = env->GetStringUTFChars(s, NULL);
|
const char *nm = env->GetStringUTFChars(s, NULL);
|
||||||
LPOLESTR nmos = A2W(nm);
|
LPOLESTR nmos = A2W(nm);
|
||||||
env->ReleaseStringUTFChars(s, nm);
|
env->ReleaseStringUTFChars(s, nm);
|
||||||
|
|||||||
@@ -81,16 +81,21 @@ JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init3
|
|||||||
|
|
||||||
BSTR typeLib = NULL;
|
BSTR typeLib = NULL;
|
||||||
if (_typelib != NULL){
|
if (_typelib != NULL){
|
||||||
|
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||||
const char *typelib = env->GetStringUTFChars(_typelib, NULL);
|
const char *typelib = env->GetStringUTFChars(_typelib, NULL);
|
||||||
typeLib = A2W(typelib);
|
typeLib = A2W(typelib);
|
||||||
|
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||||
|
|
||||||
//printf("we have a type lib %ls\n",typeLib);
|
//printf("we have a type lib %ls\n",typeLib);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find progid if any
|
// find progid if any
|
||||||
LPOLESTR bsProgId = NULL;
|
LPOLESTR bsProgId = NULL;
|
||||||
if (_progid!=NULL) {
|
if (_progid!=NULL) {
|
||||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||||
|
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||||
bsProgId = A2W(progid);
|
bsProgId = A2W(progid);
|
||||||
|
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||||
//printf("we have an applicaton %ls\n",bsProgId);
|
//printf("we have an applicaton %ls\n",bsProgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -558,24 +558,26 @@ JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromStringArray
|
|||||||
V_VT(&v) = VT_BSTR;
|
V_VT(&v) = VT_BSTR;
|
||||||
for(int i=0;i<len;i++) {
|
for(int i=0;i<len;i++) {
|
||||||
jstring s = (jstring)env->GetObjectArrayElement(a, i);
|
jstring s = (jstring)env->GetObjectArrayElement(a, i);
|
||||||
const char *str = env->GetStringUTFChars(s, NULL);
|
// jacob report 1224219 should use unicode and not UTF-8 (Variant modified in previous report
|
||||||
|
const jchar *str = env->GetStringChars(s, NULL);
|
||||||
CComBSTR bs(str);
|
CComBSTR bs(str);
|
||||||
V_VT(&v) = VT_BSTR;
|
V_VT(&v) = VT_BSTR;
|
||||||
V_BSTR(&v) = bs.Copy();
|
V_BSTR(&v) = bs.Copy();
|
||||||
long x = i;
|
long x = i;
|
||||||
SafeArrayPutElement(psa,&x,&v);
|
SafeArrayPutElement(psa,&x,&v);
|
||||||
env->ReleaseStringUTFChars(s, str);
|
env->ReleaseStringChars(s, str);
|
||||||
VariantClear(&v);
|
VariantClear(&v);
|
||||||
}
|
}
|
||||||
} else if (vt == VT_BSTR) {
|
} else if (vt == VT_BSTR) {
|
||||||
for(int i=0;i<len;i++) {
|
for(int i=0;i<len;i++) {
|
||||||
jstring s = (jstring)env->GetObjectArrayElement(a, i);
|
jstring s = (jstring)env->GetObjectArrayElement(a, i);
|
||||||
const char *str = env->GetStringUTFChars(s, NULL);
|
// jacob report 1224219 should use unicode and not UTF-8 (Variant modified in previous report
|
||||||
|
const jchar *str = env->GetStringChars(s, NULL);
|
||||||
CComBSTR bs(str);
|
CComBSTR bs(str);
|
||||||
BSTR bstr = bs.Detach();
|
BSTR bstr = bs.Detach();
|
||||||
long x = i;
|
long x = i;
|
||||||
SafeArrayPutElement(psa,&x,bstr);
|
SafeArrayPutElement(psa,&x,bstr);
|
||||||
env->ReleaseStringUTFChars(s, str);
|
env->ReleaseStringChars(s, str);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ThrowComFail(env, "safearray cannot be assigned from string\n", 0);
|
ThrowComFail(env, "safearray cannot be assigned from string\n", 0);
|
||||||
@@ -1613,11 +1615,17 @@ JNIEXPORT jstring JNICALL Java_com_jacob_com_SafeArray_getString__I
|
|||||||
}
|
}
|
||||||
BSTR bs = V_BSTR(&v);
|
BSTR bs = V_BSTR(&v);
|
||||||
jstring js = env->NewString(bs, SysStringLen(bs));
|
jstring js = env->NewString(bs, SysStringLen(bs));
|
||||||
|
// jacob report 1224219
|
||||||
|
// SafeArrayGetElement memory must be freed http://www.canaimasoft.com/f90VB/OnlineManuals/Reference/TH_31.htm
|
||||||
|
VariantClear(&v);
|
||||||
return js;
|
return js;
|
||||||
} else if (vt == VT_BSTR) {
|
} else if (vt == VT_BSTR) {
|
||||||
BSTR bs = NULL;
|
BSTR bs = NULL;
|
||||||
SafeArrayGetElement(psa, &idx, &bs);
|
SafeArrayGetElement(psa, &idx, &bs);
|
||||||
jstring js = env->NewString(bs, SysStringLen(bs));
|
jstring js = env->NewString(bs, SysStringLen(bs));
|
||||||
|
// jacob report 1224219
|
||||||
|
// SafeArrayGetElement memory must be freed http://www.canaimasoft.com/f90VB/OnlineManuals/Reference/TH_31.htm
|
||||||
|
if (bs) free(bs);
|
||||||
return js;
|
return js;
|
||||||
}
|
}
|
||||||
ThrowComFail(env, "safearray cannot get string", 0);
|
ThrowComFail(env, "safearray cannot get string", 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user