需要帮助解决内存泄漏错误

时间:2016-10-23 06:53:59

标签: c++ memory-leaks

当我运行valgrind时,我在操作符new的方法插入时遇到一个错误; 我知道这可能意味着我必须删除节点n我是如何尝试这么多东西尝试删除它但它只是给了我更多的错误。请帮忙。

<html>
    <style>
        body {
            margin: 0px;
            padding: 0px;
        }
    </style>

    <body>
        <canvas id = "myCanvas" position = "absolute" width = "500" height = "500" style = "border: 1px solid #000000"></canvas>
        <canvas id = "sidebar" position = "absolute" width = "100" height = "500" style = "border: 1px solid #000000"></canvas>
        <script>
            var canvas = document.getElementById(myCanvas);
            var side = document.getElementById(sidebar);
            var ctx = canvas.getContext("2d");
            function drawUser() {
                ctx.fillStyle = "#000000";
                ctx.strokeStyle = "#000000";
                ctx.beginPath();
                ctx.moveTo(240, 500);
                ctx.lineTo(250, 490);
                ctx.lineTo(260, 500);
                ctx.lineTo(250, 495);
                ctx.closePath();
                ctx.stroke();
            }
            drawUser();
        </script>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

if(v.size() == 0) { //empty list v.push_back(key); n = new node; n->prev = NULL; n->key = key; n->values.push_back(value); head = n; tail = n; } 方法中:

head->next

您没有将 while(temp != NULL) { // <<<<< Is temp uninitialized? if (temp->key == key) { temp->values.push_back(value); break; } else temp = temp->next; 设置为NULL。我怀疑在插入第二个值时可能会出现问题。

var result = _appDbContext.Personalization_Mapping.OrderByDescending(x => x.ID)
.GroupBy(x => x.CustomerID)
.Select(g => new {g, count= g.Count()})
.SelectMany(t => t.g.Select(b => b)
.Zip(Enumerable.Range(1,t.count), (j,i) => new {j.Property1, j.Property2, rn = i}));

不将指针初始化为NULL

非常危险