[PATCH] D114337: Support Windows

Dmitry Vassiliev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 25 09:42:03 PST 2021


slydiman added inline comments.


================
Comment at: lnt/testing/profile/cPerf.cpp:405
       ssize_t Len = getline(&Line, &LineLen, Stream);
       if (Len == -1)
         break;
----------------
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.


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