[PATCH] D114337: Support Windows
Danila Malyutin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 25 11:28:46 PST 2021
danilaml added inline comments.
================
Comment at: lnt/testing/profile/cPerf.cpp:405
ssize_t Len = getline(&Line, &LineLen, Stream);
if (Len == -1)
break;
----------------
slydiman wrote:
> danilaml wrote:
> > kpdev42 wrote:
> > > danilaml wrote:
> > > > I think there is a potential mem leak here, but that's not critical.
> > > Please look at the code `if (Line) free(Line);` below.
> > From the quick glance it looks like if `realloc` succeeds once inside the added `getline` function but fails the second time, `-1` is returned with `lineptr` still pointing to the old non-realloced buffer, so there will potentially be a double free as well. I might be reading it wrong however.
> Please look at the example on Microsoft doc https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/realloc
> ```
> // Reallocate and show new size:
> oldbuffer = buffer; // save pointer in case realloc fails
> if ( (buffer = realloc(buffer, size + (1000 * sizeof(long)) ) ) == NULL)
> {
> free(oldbuffer); // free original block
> exit(1);
> }
> ```
> So everything is correct according to this example.
I don't see it. The situation I'm talking about is akin to:
```oldbuffer = buffer; // save pointer in case realloc fails
if ( (buffer = realloc(buffer, size + (1000 * sizeof(long)) ) ) == NULL) // succeeds
{
free(oldbuffer);
exit(1);
}
// oldbuffer is pointing to the old, potentially freed buffer, buffer != oldbuffer
size += ...
if ( (buffer = realloc(buffer, size + (1000 * sizeof(long)) ) ) == NULL) // fails
{
free(oldbuffer); // buffer is not freed, oldbuffer is freed the second time
}
```
Here, `oldbuffer` would
Repository:
rLNT LNT
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D114337/new/
https://reviews.llvm.org/D114337
More information about the llvm-commits
mailing list