寒江独钓前辈的第一个例子的部分分析
来源:互联网 发布:macbook air装windows 编辑:程序博客网 时间:2024/05/16 08:20
分析了一下其源代码,不是很复杂,不过对其中的一段代码不太清楚。
// 打开设备对象
*status = IoGetDeviceObjectPointer(&name_str, FILE_ALL_ACCESS, &fileobj, &devobj);
if (*status == STATUS_SUCCESS)
ObDereferenceObject(fileobj);
*status = IoGetDeviceObjectPointer(&name_str, FILE_ALL_ACCESS, &fileobj, &devobj);
if (*status == STATUS_SUCCESS)
ObDereferenceObject(fileobj);
书上是说如果IoGetDeviceObjectPointer 成功,需要调用ObDereferenceObject 来解除引用,否则会引起内存泄漏。
始终没搞明白,怎么就内存泄漏了。 后来在网上搜了一下微软官网
https://technet.microsoft.com/zh-cn/ff549198(v=vs.80)
里面有详细的介绍。
This routine also returns a pointer to the corresponding file object. When unloading, a driver can dereference the file object as a means of indirectly dereferencing the device object. To do so, the driver calls ObDereferenceObject from its Unload routine, passing the file object pointer returned by IoGetDeviceObjectPointer.
根据其描述,应该是在驱动卸载的时候,必须要调用ObDereferenceObject,将当初使用IoGetDeviceObjectPointer 函数的引用解除。
所以个人认为其实该操作可以在卸载驱动的时候调用。 当然了,如果到那个时候调用的话,需要保存其入参,这样考虑的话,放在 IoGetDeviceObjectPointer 成功的时候调用,实现上是最方便的。
通过 http://download.csdn.net/download/ftyou2000/3944539 里面的工具确实可以看出,我们的驱动对象下有一个设备对象。 (目前本机器只有一个串口)
0 0
- 寒江独钓前辈的第一个例子的部分分析
- 寒江独钓前辈的第一个例子的编译运行过程
- Corba的第一个例子
- D3D的第一个例子
- freemarker的第一个例子
- TC的第一个例子
- webservice的第一个例子
- struts2的第一个例子
- freemarker的第一个例子
- Ajax的第一个例子
- spring的第一个例子
- springAOP的第一个例子
- Netty的第一个例子
- storm的第一个例子
- spring aop学习的第一个例子
- spring 开始的第一个例子
- 创建OGRE的第一个例子
- 成功运行RMI的第一个例子
- 在Eclipse添加Android兼容包( v4、v7 appcompat )
- 94.Examine the structure of the PROGRAMS table:
- js动态提示输入框剩余字符数
- 结构型:设计模式之适配器模式(六)
- 【HTML第二本】HTML.5与CSS.3权威指南 HTML5部分读书笔记
- 寒江独钓前辈的第一个例子的部分分析
- Shell脚本获取格式化日期与时间总结
- leetcode:88 Merge Sorted Array-每日编程第三十一题
- 浅析TCP RST
- Hibernate映射类型
- Android使用动画的注意事项
- C#Asp.Net中mongo数据库的基本使用
- 使用Zxing生成带logo的二维码
- poj 2236 Wireless Network 并查集