程序退出时JNA错误
JNA Error at Program Exit
所以我在c++中有以下代码
__declspec(dllexport) extern "C"
char** get_prop_types( int* count ) {
const vector<string>& r = prop_manager::get_prop_types();
char **p = (char**)malloc( r.size() );
char **ptr = p;
for( vector<string>::const_iterator it = r.begin(); it!=r.end() ; ++it ) {
*p = (char*)malloc( it->size() );
strcpy(*p++,it->c_str());
}
*count = r.size();
return ptr;
}
和java
public interface Arch extends Library {
public Pointer get_prop_types( IntByReference size );
}
static Arch theLib; //initialization not shown
public static String[] getPropTypes() {
IntByReference size = new IntByReference();
Pointer strs = theLib.get_prop_types(size);
//free is apparently handled for us?
return strs.getStringArray(0, size.getValue());
}
public static void main( String[] args ) {
System.out.println( Arrays.toString(getPropTypes()) );
}
上面的语句将打印出一个string列表。到目前为止一切顺利。但是在main返回之后(在结束期间?)在
这几行出现错误The instruction at "%08X" referenced memory at "%08x". The memory could not be "read".
当尝试手动free()
char**
或每个单独的char*
时,我得到相同的错误
This:
*p = (char*)malloc( it->size() );
应: *p = (char*)malloc( it->size() + 1);
我刚刚注意到:
char **p = (char**)malloc( r.size() );
应: char **p = (char**)malloc( r.size() * sizeof(char *) );
显示了这些天我使用malloc的频率!
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- JNA结构字段值错误
- JNA 和 C++ - 导致不满意链接错误的简约示例
- JNA/BridJ 等中的分段错误
- JNA -结构创建错误
- 程序退出时JNA错误