Closed Bug 89539 Opened 23 years ago Closed 23 years ago

Memory leak

Categories

(Core :: Networking, defect, P4)

x86
All
defect

Tracking

()

RESOLVED FIXED

People

(Reporter: vda, Assigned: timeless)

Details

(Keywords: memory-leak)

Attachments

(1 file)

nsProtocolProxyService.cpp:
571         hp = new host_port();
572         if (!hp)
573             return; // fail silently
574         hp->host = new nsCString(np, endproxy-np);
575         if (!hp->host)
576             return;
577         hp->port = nport>0 ? nport : -1;

second 'if' should do 'delete hp' before return.
Visit http://hands.stanford.edu/linux/ - automatic checker for such things.
Mozilla already use LXR, what about using MC described at this url?
->Networking
Assignee: asa → neeti
Status: UNCONFIRMED → NEW
Component: Browser-General → Networking
Ever confirmed: true
QA Contact: doronr → benc
nsProtocolProxyService::AddNoProxyFor(const char* iHost, PRInt32 iPort)
{
    if (!iHost)
        return NS_ERROR_NULL_POINTER;

    host_port* hp = new host_port();
    if (!hp)
        return NS_ERROR_OUT_OF_MEMORY;
    hp->host = new nsCString(iHost);
    hp->port = iPort;    

-style looks a bit off, and also doesn't check to see if hp->host failed...

scc: can these things actually happen? blame says gagan.
Assignee: neeti → gagan
Keywords: mlk
OS: other → All
even though this is a rare edge case, any leaks when we are already on low 
memory are bad. So here is a patch--

Index: nsProtocolProxyService.cpp
===================================================================
RCS file: /cvsroot/mozilla/netwerk/base/src/nsProtocolProxyService.cpp,v
retrieving revision 1.24
diff -u -r1.24 nsProtocolProxyService.cpp
--- nsProtocolProxyService.cpp  2001/06/17 05:21:52     1.24
+++ nsProtocolProxyService.cpp  2001/07/06 19:58:01
@@ -486,10 +486,13 @@
     if (!hp)
         return NS_ERROR_OUT_OF_MEMORY;
     hp->host = new nsCString(iHost);
+    if (!hp->host) {
+        delete hp;
+        return NS_ERROR_OUT_OF_MEMORY;
+    }
     hp->port = iPort;

     nsAutoLock lock(mArrayLock);
-
     return (mFiltersArray.AppendElement(hp)) ? NS_OK : NS_ERROR_FAILURE;
 }
Keywords: patch
Priority: -- → P4
Target Milestone: --- → mozilla0.9.3
Attached patch both patchesSplinter Review
(although putting the second opening brace on the same line would probably be
preferable)
--> timeless for checkin
Assignee: gagan → timeless
Target Milestone: mozilla0.9.3 → ---
Is the bracing style the same as the rest of the file in the second part of the
patch?  It's quite jarring.  Other than that sr=blizzard
fixed
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: