Closed Bug 1268387 Opened 4 years ago Closed 4 years ago

[Static Analysis][Resource leak] In function nsHttpChannel::ForceCacheEntryValidFor

Categories

(Core :: Networking, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1358787, [necko-active])

Attachments

(1 file)

The Static Analysis tool Coverity added that ToNewCString(key) leaks memory in: 

    } else {
        mCacheEntry->ForceValidFor(aSecondsToTheFuture);

        nsAutoCString key;
        mCacheEntry->GetKey(key);

        LOG(("nsHttpChannel::ForceCacheEntryValidFor successfully forced valid "
             "entry with key %s for %d seconds. [this=%p]", ToNewCString(key),
             aSecondsToTheFuture, this));
    }

This should be fixed by freeing the memory allocated by ToNewCString(key).
(In reply to Andi-Bogdan Postelnicu from comment #0) 
> This should be fixed by freeing the memory allocated by ToNewCString(key).

Can't we just use key.get() instead of allocating?
Whiteboard: CID 1358787 → CID 1358787, [necko-active]
Comment on attachment 8746424 [details]
MozReview Request: Bug 1268387 - avoid memory leak of ToNewCString(key). r?valentin

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/49423/diff/1-2/
(In reply to Valentin Gosu [:valentin] from comment #2)
> (In reply to Andi-Bogdan Postelnicu from comment #0) 
> > This should be fixed by freeing the memory allocated by ToNewCString(key).
> 
> Can't we just use key.get() instead of allocating?

sure why not, just updated the patch.
Comment on attachment 8746424 [details]
MozReview Request: Bug 1268387 - avoid memory leak of ToNewCString(key). r?valentin

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/49423/diff/2-3/
Attachment #8746424 - Attachment description: MozReview Request: Bug 1268387 - avoid memory leak of ToNewCString(key). r?mcmanus → MozReview Request: Bug 1268387 - avoid memory leak of ToNewCString(key). r?valentin
Attachment #8746424 - Flags: review?(mcmanus) → review?(valentin.gosu)
Comment on attachment 8746424 [details]
MozReview Request: Bug 1268387 - avoid memory leak of ToNewCString(key). r?valentin

https://reviewboard.mozilla.org/r/49423/#review46273

Thanks!
Attachment #8746424 - Flags: review?(valentin.gosu) → review+
https://hg.mozilla.org/mozilla-central/rev/a29de45d453b
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.