linux - C++ dlsym Pointer Function Problems -


i calling function shared object (a.so) inside shared object jni interface (b.so). loaded a.so using dlopen , mapped function using dlsym.

here part of code:

int (*ptestcall)(char* szmsgout);   //open shared object , create handler handle = dlopen (filename, rtld_lazy | rtld_global);   //map adrress of function inside shared object function pointer *(void **) (&ptestcall) = dlsym(handle, "_zn7ipslink9testcallelllpc");     int ret = ptestcall(szmsgout); 

in log of a.so can see testcall called , finished it's job when tries write output szmsgout buffer crashes. if remove output writing buffer go ok without problem.

can explain problem or why crashes?

here example:

jniexport jint jnicall java_linux_wrapperlinux_payment(jnienv *env, jobject obj, jchararray jmsgout){ int retval = false; char clog[1024] = ""; //get len of passed buffer int len = env->getarraylength(jmsgout); char *szmsgout; szmsgout = (char*) malloc (len); memset(szmsgout, 0x00, len); //call function retval = testcalltry(szmsgout); // copy result out of c character buffer jchar buffer.  converting chars jchars. jchar *jcharbuffer = (jchar *)calloc(sizeof(jchar), len); int templen = strlen(szmsgout); (int = 0; < templen; ++){     jcharbuffer[i] = (jchar)szmsgout[i]; } if(templen > 0) // copy result jchararray. env->setchararrayregion(jmsgout, 0, len, jcharbuffer); // free jchar buffer free(jcharbuffer); free(szmsgout); return retval; }  int (*ptestcall)(char* szmsgout);  int testcalltry(char *szmsgout){ void *handle; char *error; char filename[150]=""; char loglocal[5000]=""; sprintf(filename,"%s/%s",path,lib_libreria); logga(filename,true); logga("loading lib",true);  //open shared object , create handler handle = dlopen (filename, rtld_lazy);  *(void **) (&ptestcall) = dlsym(handle, "_zn7ipslink9testcallelllpc"); int ret = ptestcall(szmsgout); dlclose(handle);  return ret;  } 

function java_linux_wrapperlinux_payment calls testcalltry.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -