String literals causing small memory leak?

前端 未结 4 1639
轮回少年
轮回少年 2020-12-22 04:10

I have a C function that is called thousands of times and I have noticed that it is the only possible place for a memory leak. I have used Valgrind and Totalview\'s

相关标签:
4条回答
  • A string literal itself does not allocate or free memory, and therefore cannot leak.

    Declaring them const won't change anything. Your problem is elsewhere.

    0 讨论(0)
  • 2020-12-22 04:52

    Could those string literals like "HEADER" and "DATA" be causing my small leak?

    Nope.

    0 讨论(0)
  • 2020-12-22 04:55

    No. A string literal has static storage duration and so its storage is reserved prior to the program startup and its lifetime is the entire execution of the program.

    0 讨论(0)
  • 2020-12-22 04:55

    Answer is yes, but it depends what does ItCreate do. Paste ItCreate function code.

    0 讨论(0)
提交回复
热议问题