- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我调用 ptsname()
时,我会得到一个 char*
返回。
联机帮助页没有指定其链接、所有权或生命周期,但 valgrind 显示它导致了泄漏(使用 --leak-check=full
)。
==46958== 128 bytes in 1 blocks are definitely lost in loss record 41 of 65
==46958== at 0x10010FEBB: malloc (in /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/vgpreload_memcheck-amd64-darwin.so)
==46958== by 0x1003F9682: ptsname (in /usr/lib/system/libsystem_c.dylib)
==46958== by 0x10001BA5F: startJob(childproc*) (unix-base.cc:211)
==46958== by 0x100019CAB: stepChild(childproc*, std::__1::function<bin::Job* (bin::Job*)>) (unix-base.cc:281)
==46958== by 0x100018F2C: bin::runJobs(std::__1::function<bin::Job* (bin::Job*)>, int) (unix-base.cc:350)
==46958== by 0x1000027FC: pmain() (bin.cc:65)
==46958== by 0x100003787: main (bin.cc:90)
然而,在free()
-ing结果时,我得到了通常的未malloc
'd错误:
bin(46690,0x7fff76531000) malloc: *** error for object 0x7fb35af00f90: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
./bootstrap.sh: line 41: 46690 Abort trap: 6 bin/bin
这是否只是该平台上 ptsname()
内部实现的泄漏,还是我应该(以某种方式)释放结果?
最佳答案
该库分配该内存,文档称该库可能会重用该内存,因此您不应该不释放它。
On success,
ptsname()
returns a pointer to a string in static storage which will be overwritten by subsequent calls. This pointer must not be freed. On failure, aNULL
pointer is returned.
The man page
您应该忽略此 valgrind 警告。您可以告诉 valgrind 为您忽略它。
--ignore-fn=<name>
Any direct heap allocation (i.e. a call tomalloc
,new
, etc, or a call to a function named by an--alloc-fn
option) that occurs in a function specified by this option will be ignored. This is mostly useful for testing purposes. This option can be specified multiple times on the command line, to name multiple functions.
The man page
关于c - 我需要释放 ptsname() 的结果吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43334567/
当我调用 ptsname() 时,我会得到一个 char* 返回。 联机帮助页没有指定其链接、所有权或生命周期,但 valgrind 显示它导致了泄漏(使用 --leak-check=full)。 =
我是一名优秀的程序员,十分优秀!