1

Topic: How you struggle with memory leaks?

Colleagues who wants and can, share, please, your methods of struggle against memory leaks and operation with curve pointers in your projects. For example, select storage strictly through yours , overload new or what that even more interesting? That I mean under struggle against curve pointers, for example: void foo (HANDLE h) {std:: vector <char> v; DWORD size = GetFileSize (h, 0); v.resize (size); ReadFile (h, &v [0]...//an exception if size == 0 i.e. such cases when it is unsafe the pointer is derived from something, as in an example. Can, too there is what that system, for example, to mark all such places with something, as that so: #define GET_PTR (x) x void foo (HANDLE h) {std:: vector <char> v;... ReadFile (h, GET_PTR (&v [0])... - when that that not clear falls, easier search in source codes to find all such places in order that when the project expanded, to shovel all source codes in search of the such is problematic. Thanks for any judgements and recommendations!

2

Re: How you struggle with memory leaks?

Hello, ksd, you wrote: ksd> colleagues who wants and can, share, please, your methods of struggle against memory leaks and operation with curve pointers in your projects. I use valgrind. Yes, I live in Linux.

3

Re: How you struggle with memory leaks?

Hello, ksd, you wrote: ksd> colleagues who wants and can, share, please, your methods of struggle against memory leaks and operation with curve pointers in your projects. ksd> for example, select storage strictly through yours , overload new or what that even more interesting? ksd> that I mean under struggle against curve pointers, for example: ksd> ksd> void foo (HANDLE h) {ksd> std:: vector <char> v; ksd> DWORD size = GetFileSize (h, 0); ksd> v.resize (size); ksd> ReadFile (h, &v [0]...//an exception if size == 0 ksd> ksd> i.e. such cases when it is unsafe the pointer is derived from something, as in an example. The main  here is a trust to the exterior data. For 0 it is simply curve, and for the big and very big files there are variants.

4

Re: How you struggle with memory leaks?

Hello, ksd, you wrote: ksd> colleagues who wants and can, share, please, your methods of struggle against memory leaks and operation with curve pointers in your projects. ksd> for example, select storage strictly through yours , overload new or what that even more interesting? , simply culture of the code. Well for example here: ksd> that I mean under struggle against curve pointers, for example: ksd> ksd> void foo (HANDLE h) {ksd> std:: vector <char> v; ksd> DWORD size = GetFileSize (h, 0); ksd> v.resize (size); ksd> ReadFile (h, &v [0]...//an exception if size == 0 ksd> would be so void foo (HANDLE h) {std:: vector <char> v; DWORD size = GetFileSize (h, 0); assert (size); <-  , it is possible for the logician  which writes to a broad gull + throws an exception in release v.resize (size); ReadFile (h, &v.at (0)...); <- - at spreads straws if the line moves to other logic}

5

Re: How you struggle with memory leaks?

Hello, ksd, you wrote: ksd> thanks for any judgements and recommendations! Obviously, clever pointers, containers and the wrappers for resource management like MutexLock if are not present in .

6

Re: How you struggle with memory leaks?

Hello, Kernan, you wrote: K> Hello, ksd, you wrote: ksd>> thanks for any judgements and recommendations! K> it is obvious, clever pointers, containers and the wrappers for resource management like MutexLock if are not present in . It just is not obvious. In such highly level difficultly happens  to find and diagnose. On me so it is better that application fell and removed , I will understand where I will eliminate. Otherwise if the error happens, let and logical, but application continued operation, on chains remaining units will work with an error.

7

Re: How you struggle with memory leaks?

Hello, Dead Down, you wrote: > It just is not obvious. In such highly level difficultly happens  to find and diagnose. On me so it is better that application fell and removed , I will understand where I will eliminate. Otherwise if the error happens, let and logical, but application continued operation, on chains remaining units will work with an error. For this purpose invented .

8

Re: How you struggle with memory leaks?

Hello, Dead Down, you wrote: > Differently if the error happens, let and logical, but application continued operation, on chains remaining units will work with an error. On what such chain? Whence it undertook? What probability of origin of such chain? Whether well to drop application, in which error in press dialogue? And if it  holding thousand connections, it is necessary to drop all of them because of an error in one of them?

9

Re: How you struggle with memory leaks?

Hello, alpha21264, you wrote: A> I Use valgrind. Yes, I live in Linux. And for Windows is umdh (yes, I on two families live)

10

Re: How you struggle with memory leaks?

Hello, Doom100500, you wrote: A>> I Use valgrind. Yes, I live in Linux. D> and for Windows is umdh (yes, I on two families live) Even it became interesting. And it only catches leaks, or an output for array boundaries too?

11

Re: How you struggle with memory leaks?

A> , simply culture of the code. Yes! But it not simply culture, and volume enough code of, how what to encode. It would be interesting to listen to your story about your culture.

12

Re: How you struggle with memory leaks?

Hello, alpha21264, you wrote: A> Hello, Doom100500, you wrote: A>>> I Use valgrind. Yes, I live in Linux. D>> and for Windows is umdh (yes, I on two families live) A> Even it became interesting. A> and it only catches leaks, or an output for array boundaries too? Only leaks

13

Re: How you struggle with memory leaks?

Hello, ksd, you wrote: ksd> colleagues who wants and can, share, please, your methods of struggle against memory leaks and operation with curve pointers in your projects. ksd> for example, select storage strictly through yours , overload new or what that even more interesting? Accuracy. For example, if I write malloc (), at once I write symmetric to it free (), without postponing on then. By the way, with leak file  it too works.

14

Re: How you struggle with memory leaks?

Hello, alpha21264, you wrote: A> I Use valgrind. Yes, I live in Linux. Valgrind is nevertheless  to be convinced that struggle against leaks was successful, instead of a method of the struggle...

15

Re: How you struggle with memory leaks?

16

Re: How you struggle with memory leaks?

Hello, ksd, you wrote: ksd> colleagues who wants and can, share, please, your methods of struggle against memory leaks and operation with curve pointers in your projects. ksd> for example, select storage strictly through yours , overload new or what that even more interesting? 1. Any resources which basically can "leak", - storage, descriptors, locks, connections, conjugate calls of type acquire/release, etc., - are located in RAII-wrappers, or become a part of classes, API which in one way or another guarantees cleaning and which cannot be used somehow differently. Perhaps, it is one of major principles. If in system there are data structures difficult and smartly connected with each other, for example no graphs already one it guarantees absence of leaks on  parts of the program code. 2. For more difficult cases the pattern "registry" is used: each object at creation is registered in "register", at corrupting deletes itself from it. The problem code locations suspected of leaks, are checked with the help registry that the amount of objects before code performance was identical. 3. Units-tests and other various tests. If they are really written and provide a comprehensible covering, the considerable part of purely technical errors (misprints, unsuccessful save-pastes, a carelessness, etc.) Are caught at the earliest stages. By the way, "the comprehensible covering" it is not mandatory 100 %, personally my experience shows that there are enough checks of basic and boundary cases, and also checks of everyones failure cases (but I will agree what to check failure cases difficult and very often on it "put a bolt"). 4. Are sometimes applied special , especially when it is necessary to test any difficult algorithm intensively working with storage. In this case the buffer submitted on an input is formed so that at once behind its termination (or before the first byte) there was a page of storage with attributes of protection ' NoAccess'. If there will be an output for buffer limits, let even only on reading, application takes immediately off with ' Access Violation '. Unfortunately, in the pure state to apply this technics not always probably (for example, because of requirements to alignment). 5. From other means: , SAL-summaries (in the core for  the code), static and dynamic analyzers (PREfast, a C ++ Code Analyzer, Driver Verifier, Application Verifier), checked-assemblages Windows... Well also it is finite, compilation at a maximum level of warnings (/W4/WX), a failure from unsafe language means (coercion in style of a C, auto:: ptr) and so on. From written the most important is, perhaps, points 1 and 3. That is, competently created architecture of application (in which it is normally strong difficult correlations is not present) with the active usage RAII, plus a test coverage. I use these techniques very much for a long time, with memory leaks and problems of "crude pointers" it was necessary to struggle seriously literally  times. Though, maybe, simply carried

17

Re: How you struggle with memory leaks?

Hello, Pzz, you wrote: Pzz> Hello, alpha21264, you wrote: A>> I Use valgrind. Yes, I live in Linux. Pzz> Valgrind is nevertheless  to be convinced that struggle against leaks was successful, instead of a method of the struggle... Somehow very thoughtfully. valgrind to me tells a place where storage has been lost. It unless not it?

18

Re: How you struggle with memory leaks?

Hello, alpha21264, you wrote: Pzz>> Valgrind is nevertheless  to be convinced that struggle against leaks was successful, instead of a method of the struggle... A> it is Somehow very thoughtful. A> valgrind to me tells a place where storage has been lost. A> it unless not it? Well, certainly it helps to live, when you not simply know that storage leaks, and understand, which. Strongly narrows down a search circle. But then all the same it is necessary to think a head. And if in advance not to think, it will be then very difficult to think. And here to think in advance, how to make so that storage did not leak is and there is a struggle.

19

Re: How you struggle with memory leaks?

Hello, Pzz, you wrote: Pzz> And here to think in advance how to make so that storage did not leak is and there is a struggle. Well, I use strategy "is released there where it was captured". If it about objects, symmetry the designer-destruktor. But here if  pieces of another's code, then valgrind.

20

Re: How you struggle with memory leaks?

Hello, alpha21264, you wrote: Pzz>> And here to think in advance how to make so that storage did not leak is and there is a struggle. A> well, I use strategy "is released there where it was captured". Clearly. Under tortures the suspect confessed. And that valgrind, valgrind...

21

Re: How you struggle with memory leaks?

Hello, alpha21264, you wrote: A> Even it became interesting. A> and it only catches leaks, or an output for array boundaries too? Only leaks by a method