Leak in Exception Code C++

前端 未结 2 1028
谎友^
谎友^ 2020-12-18 17:04

I\'ve been working with a school project, and one of the tasks is to make sure it doesn\'t leak at all. So, I ran my program through valgrind, and because I\'m not using an

2条回答
  •  遥遥无期
    2020-12-18 17:24

    It's important to understand the difference between leaking memory on a repeated basis (which can lead to exhaustion), and having some underlying support code or library have a one-off intialisation step that gets some heap memory it will use while the program runs (in which case it's not really useful or necessary to free/delete the memory at program termination, and it may be quite a hassle trying to arrange it).

    Here, __cxa_get_globals seems to be doing a one-off malloc.

    Short story: just make sure you don't get multiple unreleased blocks (or a bigger one) when those exceptions are called repeatedly....

提交回复
热议问题