Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 1 | From 9ff06108cd44e84ba6c68bfa6737e793f117e303 Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | From: Nate Karstens <nate.karstens@garmin.com> |
| 3 | Date: Thu, 10 Aug 2017 08:46:03 -0500 |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 4 | Subject: [PATCH] Change a dynamic allocation to file-scope variable |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | |
| 6 | Changes a variable from being dynamically-allocated to being |
| 7 | statically-allocated at the file scope. Addresses a Coverity |
| 8 | issue where it appeared that the memory was being leaked. |
| 9 | |
| 10 | Upstream-Status: Submitted [dts@apple.com] |
| 11 | |
| 12 | Signed-off-by: Nate Karstens <nate.karstens@garmin.com> |
| 13 | --- |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 14 | mDNSPosix/mDNSPosix.c | 14 ++++---------- |
| 15 | 1 file changed, 4 insertions(+), 10 deletions(-) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 16 | |
| 17 | diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 18 | index 7aeee7b..2d25016 100755 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 19 | --- a/mDNSPosix/mDNSPosix.c |
| 20 | +++ b/mDNSPosix/mDNSPosix.c |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 21 | @@ -81,6 +81,7 @@ static sigset_t gEventSignalSet; // Signals which event loop list |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 22 | static sigset_t gEventSignals; // Signals which were received while inside loop |
| 23 | |
| 24 | static PosixNetworkInterface *gRecentInterfaces; |
| 25 | +static IfChangeRec gChgRec; |
| 26 | |
| 27 | // *************************************************************************** |
| 28 | // Globals (for debugging) |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 29 | @@ -1641,18 +1642,11 @@ mDNSlocal void InterfaceChangeCallback(int fd, void *context) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 30 | mDNSlocal mStatus WatchForInterfaceChange(mDNS *const m) |
| 31 | { |
| 32 | mStatus err; |
| 33 | - IfChangeRec *pChgRec; |
| 34 | |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 35 | - pChgRec = (IfChangeRec*) mDNSPlatformMemAllocateClear(sizeof *pChgRec); |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 36 | - if (pChgRec == NULL) |
| 37 | - return mStatus_NoMemoryErr; |
| 38 | - |
| 39 | - pChgRec->mDNS = m; |
| 40 | - err = OpenIfNotifySocket(&pChgRec->NotifySD); |
| 41 | + gChgRec.mDNS = m; |
| 42 | + err = OpenIfNotifySocket(&gChgRec.NotifySD); |
| 43 | if (err == 0) |
| 44 | - err = mDNSPosixAddFDToEventLoop(pChgRec->NotifySD, InterfaceChangeCallback, pChgRec); |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 45 | - if (err) |
| 46 | - mDNSPlatformMemFree(pChgRec); |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 47 | + err = mDNSPosixAddFDToEventLoop(gChgRec.NotifySD, InterfaceChangeCallback, &gChgRec); |
| 48 | |
| 49 | return err; |
| 50 | } |
| 51 | -- |
Andrew Geissler | d688a01 | 2020-09-18 13:36:00 -0500 | [diff] [blame] | 52 | 2.20.1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 53 | |