blob: d9adde04c2233aa1acfa6104cc829dffe378a6e8 [file] [log] [blame]
Andrew Geisslerd688a012020-09-18 13:36:00 -05001From 9ff06108cd44e84ba6c68bfa6737e793f117e303 Mon Sep 17 00:00:00 2001
Andrew Geissler82c905d2020-04-13 13:39:40 -05002From: Nate Karstens <nate.karstens@garmin.com>
3Date: Thu, 10 Aug 2017 08:46:03 -0500
Andrew Geisslerd688a012020-09-18 13:36:00 -05004Subject: [PATCH] Change a dynamic allocation to file-scope variable
Andrew Geissler82c905d2020-04-13 13:39:40 -05005
6Changes a variable from being dynamically-allocated to being
7statically-allocated at the file scope. Addresses a Coverity
8issue where it appeared that the memory was being leaked.
9
10Upstream-Status: Submitted [dts@apple.com]
11
12Signed-off-by: Nate Karstens <nate.karstens@garmin.com>
13---
Andrew Geisslerd688a012020-09-18 13:36:00 -050014 mDNSPosix/mDNSPosix.c | 14 ++++----------
15 1 file changed, 4 insertions(+), 10 deletions(-)
Andrew Geissler82c905d2020-04-13 13:39:40 -050016
17diff --git a/mDNSPosix/mDNSPosix.c b/mDNSPosix/mDNSPosix.c
Andrew Geisslerd688a012020-09-18 13:36:00 -050018index 7aeee7b..2d25016 100755
Andrew Geissler82c905d2020-04-13 13:39:40 -050019--- a/mDNSPosix/mDNSPosix.c
20+++ b/mDNSPosix/mDNSPosix.c
Andrew Geisslerd688a012020-09-18 13:36:00 -050021@@ -81,6 +81,7 @@ static sigset_t gEventSignalSet; // Signals which event loop list
Andrew Geissler82c905d2020-04-13 13:39:40 -050022 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 Geisslerd688a012020-09-18 13:36:00 -050029@@ -1641,18 +1642,11 @@ mDNSlocal void InterfaceChangeCallback(int fd, void *context)
Andrew Geissler82c905d2020-04-13 13:39:40 -050030 mDNSlocal mStatus WatchForInterfaceChange(mDNS *const m)
31 {
32 mStatus err;
33- IfChangeRec *pChgRec;
34
Andrew Geisslerd688a012020-09-18 13:36:00 -050035- pChgRec = (IfChangeRec*) mDNSPlatformMemAllocateClear(sizeof *pChgRec);
Andrew Geissler82c905d2020-04-13 13:39:40 -050036- 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 Geisslerd688a012020-09-18 13:36:00 -050045- if (err)
46- mDNSPlatformMemFree(pChgRec);
Andrew Geissler82c905d2020-04-13 13:39:40 -050047+ err = mDNSPosixAddFDToEventLoop(gChgRec.NotifySD, InterfaceChangeCallback, &gChgRec);
48
49 return err;
50 }
51--
Andrew Geisslerd688a012020-09-18 13:36:00 -0500522.20.1
Andrew Geissler82c905d2020-04-13 13:39:40 -050053