{"action":"opened","issue":{"url":"https://api.github.com/repos/stan-dev/stan/issues/1293","labels_url":"https://api.github.com/repos/stan-dev/stan/issues/1293/labels{/name}","comments_url":"https://api.github.com/repos/stan-dev/stan/issues/1293/comments","events_url":"https://api.github.com/repos/stan-dev/stan/issues/1293/events","html_url":"https://github.com/stan-dev/stan/issues/1293","id":57618513,"number":1293,"title":"memory leaking (no delete after new)","user":{"login":"maverickg","id":68500,"avatar_url":"https://avatars.githubusercontent.com/u/68500?v=3","gravatar_id":"","url":"https://api.github.com/users/maverickg","html_url":"https://github.com/maverickg","followers_url":"https://api.github.com/users/maverickg/followers","following_url":"https://api.github.com/users/maverickg/following{/other_user}","gists_url":"https://api.github.com/users/maverickg/gists{/gist_id}","starred_url":"https://api.github.com/users/maverickg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maverickg/subscriptions","organizations_url":"https://api.github.com/users/maverickg/orgs","repos_url":"https://api.github.com/users/maverickg/repos","events_url":"https://api.github.com/users/maverickg/events{/privacy}","received_events_url":"https://api.github.com/users/maverickg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-13T16:17:22Z","updated_at":"2015-02-13T16:17:22Z","closed_at":null,"body":"During debugging a different problem, I noticed there are memory leaking.  Valgrind indicates there are a lot of `new` used in https://github.com/stan-dev/stan/blob/develop/src/stan/services/command.hpp, but not necessarily there is a `delete` for all the possibilities of exit from this function `command`. \r\n\r\nBelow is just an output of using valgrind from running the model with test gradient mode (cmdstan 2.6.0), which shows at line [70](https://github.com/stan-dev/stan/blob/v2.6.0/src/stan/common/command.hpp#L70), 71, 72, 73, 74, 134 there is a new, but in this case, no delete afterwards.\r\n\r\n```\r\n==4851== Memcheck, a memory error detector\r\n==4851== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.\r\n==4851== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info\r\n==4851== Command: ./binormal diagnose\r\n==4851== \r\nmethod = diagnose\r\n  diagnose\r\n    test = gradient (Default)\r\n      gradient\r\n        epsilon = 9.9999999999999995e-07 (Default)\r\n        error = 9.9999999999999995e-07 (Default)\r\nid = 0 (Default)\r\ndata\r\n  file =  (Default)\r\ninit = 2 (Default)\r\nrandom\r\n  seed = 2256238639\r\noutput\r\n  file = output.csv (Default)\r\n  diagnostic_file =  (Default)\r\n  refresh = 100 (Default)\r\n\r\n\r\nTEST GRADIENT MODE\r\n\r\nLog probability=-1.49583\r\n\r\nparam idx           value           model     finite diff           error\r\n        0        -1.71648         1.69507         1.69507      1.2689e-10\r\n        1       -0.383584        0.214078        0.214078    -1.67667e-10\r\n==4851== \r\n==4851== HEAP SUMMARY:\r\n==4851==     in use at exit: 25,075 bytes in 346 blocks\r\n==4851==   total heap usage: 699 allocs, 353 frees, 102,872 bytes allocated\r\n==4851== \r\n==4851== 242 (80 direct, 162 indirect) bytes in 1 blocks are definitely lost in loss record 338 of 346\r\n==4851==    at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==4851==    by 0x4291E3: int stan::common::command<binormal_model_namespace::binormal_model>(int, char const**) (command.hpp:70)\r\n==4851==    by 0x4096EB: main (main.cpp:7)\r\n==4851== \r\n==4851== 434 (56 direct, 378 indirect) bytes in 1 blocks are definitely lost in loss record 339 of 346\r\n==4851==    at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==4851==    by 0x429218: int stan::common::command<binormal_model_namespace::binormal_model>(int, char const**) (command.hpp:71)\r\n==4851==    by 0x4096EB: main (main.cpp:7)\r\n==4851== \r\n==4851== 447 (56 direct, 391 indirect) bytes in 1 blocks are definitely lost in loss record 340 of 346\r\n==4851==    at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==4851==    by 0x429282: int stan::common::command<binormal_model_namespace::binormal_model>(int, char const**) (command.hpp:73)\r\n==4851==    by 0x4096EB: main (main.cpp:7)\r\n==4851== \r\n==4851== 457 (96 direct, 361 indirect) bytes in 1 blocks are definitely lost in loss record 341 of 346\r\n==4851==    at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==4851==    by 0x42924D: int stan::common::command<binormal_model_namespace::binormal_model>(int, char const**) (command.hpp:72)\r\n==4851==    by 0x4096EB: main (main.cpp:7)\r\n==4851== \r\n==4851== 1,116 (56 direct, 1,060 indirect) bytes in 1 blocks are definitely lost in loss record 343 of 346\r\n==4851==    at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==4851==    by 0x4292B7: int stan::common::command<binormal_model_namespace::binormal_model>(int, char const**) (command.hpp:74)\r\n==4851==    by 0x4096EB: main (main.cpp:7)\r\n==4851== \r\n==4851== 8,720 (528 direct, 8,192 indirect) bytes in 1 blocks are definitely lost in loss record 345 of 346\r\n==4851==    at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==4851==    by 0x429863: int stan::common::command<binormal_model_namespace::binormal_model>(int, char const**) (command.hpp:134)\r\n==4851==    by 0x4096EB: main (main.cpp:7)\r\n==4851== \r\n==4851== 13,091 (80 direct, 13,011 indirect) bytes in 1 blocks are definitely lost in loss record 346 of 346\r\n==4851==    at 0x4C29180: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)\r\n==4851==    by 0x41B99D: stan::gm::argument_parser::argument_parser(std::vector<stan::gm::argument*, std::allocator<stan::gm::argument*> >&) (argument_parser.hpp:25)\r\n==4851==    by 0x4292FB: int stan::common::command<binormal_model_namespace::binormal_model>(int, char const**) (command.hpp:76)\r\n==4851==    by 0x4096EB: main (main.cpp:7)\r\n==4851== \r\n==4851== LEAK SUMMARY:\r\n==4851==    definitely lost: 952 bytes in 7 blocks\r\n==4851==    indirectly lost: 23,555 bytes in 338 blocks\r\n==4851==      possibly lost: 0 bytes in 0 blocks\r\n==4851==    still reachable: 568 bytes in 1 blocks\r\n==4851==         suppressed: 0 bytes in 0 blocks\r\n==4851== Reachable blocks (those to which a pointer was found) are not shown.\r\n==4851== To see them, rerun with: --leak-check=full --show-leak-kinds=all\r\n==4851== \r\n==4851== For counts of detected and suppressed errors, rerun with: -v\r\n==4851== ERROR SUMMARY: 7 errors from 7 contexts (suppressed: 0 from 0)\r\n```"}}