setprop libc.debug.malloc = 1不工作 [英] setprop libc.debug.malloc = 1 is not working

查看:1188
本文介绍了setprop libc.debug.malloc = 1不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用setprop libc.debug.malloc = 1,找出泄漏。
我在该提出的演示程序,并介绍内存泄漏,但在上述标志不能够检测到这个泄漏。
我想下面的命令:
亚行外壳setprop libc.debug.malloc 1
亚行的shell停止
亚行的shell启动

I tried to use setprop libc.debug.malloc = 1 to find out leak. I made an demo program and introduced memory leak in that but the above flag is not able to detect this leak. I tried below commands: adb shell setprop libc.debug.malloc 1 adb shell stop adb shell start

jstring Java_com_example_hellojni_HelloJni_stringFromJNI(JNIEnv* env,
jobject thiz) {
int *p = malloc(sizeof(int));
p[1] = 100;
return (*env)->NewStringUTF(env, "Hello from JNI !");
}

任何帮助将是AP preciated。

Any help would be appreciated.

感谢

推荐答案

libc.debug.malloc 不Valgrind的。它跟踪本地堆分配,但并没有真正直接检测泄漏。它的工作原理最好在DDMS一起选择;看<一个href=\"http://stackoverflow.com/questions/15386339/how-to-use-ddms-for-memory-leaks-in-c-$c$c/15398651#15398651\">this回答了解有关使用其原生泄漏追逐(也许<一个href=\"http://stackoverflow.com/questions/3768463/detecting-native-memory-leaks-in-android-jni-$c$c/3773507#3773507\">this旧的答案)。

libc.debug.malloc is not valgrind. It tracks native heap allocations, but doesn't really detect leaks directly. It works best in conjuction with DDMS; see this answer for information about using it for native leak chasing (and maybe this older answer).

(注意你的可以的使用的valgrind最近的Andr​​oid版本,但得到它设置可以是一个冒险。)

(Note you can use valgrind on recent versions of Android, but getting it set up can be an adventure.)

FWIW,不同层次的 libc.debug.malloc 在查找相当不错的用后自由和缓冲区溢出:

FWIW, different levels of libc.debug.malloc are reasonably good at finding use-after-free and buffer overruns:

/* 1  - For memory leak detections.
 * 5  - For filling allocated / freed memory with patterns defined by
 *      CHK_SENTINEL_VALUE, and CHK_FILL_FREE macros.
 * 10 - For adding pre-, and post- allocation stubs in order to detect
 *      buffer overruns.

例如,如果您设置 libc.debug.malloc = 10 并添加免费()来电以上你的榜样,你很可能会从库中得到一个警告消息,因为你设置 p [1] ,而不是 p [0]

For example, if you set libc.debug.malloc = 10 and add a free() call to your example above, you'll likely get a warning message from the library because you set p[1] rather than p[0].

这篇关于setprop libc.debug.malloc = 1不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆