Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Memory leaks from dc_field_add_string

未关闭
#129 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c
领域
backend

调研方向

Start in libdivecomputer/src/field-cache.c and trace dc_parser_deallocate through the three parsers that use dc_field_cache, including shearwater_predator_parser.c. Reproduce the download with dctool under ASAN, inspect each parser's destroy path, and verify that cached strings are released without leaks.

由索引模型根据 Issue 内容生成。

描述

When doing a download, with example dctool, built with asan, one can clearly see the memory leaks from the strdup happening in the field-cache:

    #0 0x7d4d7b32478c in strdup ../../../../src/libsanitizer/asan/asan_interceptors.cpp:617
    #1 0x645f8c5da40f in dc_field_add_string ../../libdivecomputer/src/field-cache.c:26
    #2 0x645f8c5da654 in dc_field_add_string_fmt ../../libdivecomputer/src/field-cache.c:52
    #3 0x645f8c561ad9 in add_sensor_state ../../libdivecomputer/src/shearwater_predator_parser.c:461
    #4 0x645f8c567043 in shearwater_predator_parser_cache ../../libdivecomputer/src/shearwater_predator_parser.c:973
    #5 0x645f8c560f4a in shearwater_predator_parser_get_datetime ../../libdivecomputer/src/shearwater_predator_parser.c:349
    #6 0x645f8c4b52e3 in dc_parser_get_datetime ../../libdivecomputer/src/parser.c:380
    #7 0x645f8c4a7cbe in dctool_xml_output_write ../../libdivecomputer/examples/output_xml.c:255
    #8 0x645f8c4a62d5 in dctool_output_write ../../libdivecomputer/examples/output.c:61
    #9 0x645f8c49ef5c in dive_cb ../../libdivecomputer/examples/dctool_download.c:92
    #10 0x645f8c56cefd in shearwater_petrel_device_foreach ../../libdivecomputer/src/shearwater_petrel.c:339
    #11 0x645f8c4b30b0 in dc_device_foreach ../../libdivecomputer/src/device.c:423
    #12 0x645f8c49fddd in download ../../libdivecomputer/examples/dctool_download.c:227
    #13 0x645f8c4a0de6 in dctool_download_run ../../libdivecomputer/examples/dctool_download.c:360
    #14 0x645f8c49d0af in main ../../libdivecomputer/examples/dctool.c:312
    #15 0x7d4d7ae2a600 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:59
    #16 0x7d4d7ae2a717 in __libc_start_main_impl ../csu/libc-start.c:360
    #17 0x645f8c499234 in _start (libdivecomputer-build/examples/dctool+0x66234) (BuildId: 506f83238fb80c0b06b6bbd4ec421c6fec390b98)

This is because the dc_parser_deallocate has no clue about the value strings kept in the struct dc_field_cache, and thus can't free them.

The 3 parsers using the dc_field_cache should either have a destroy function added to them which frees the cached strings or have their existing destroy function updated to free the cached strings.

主要语言
C
星标
126
派生
116
平均合并
2 天 13 小时
30 天内合并 PR
13

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

subsurface/libdc 的其他 Issue

查看 subsurface/libdc 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。