The default bug view has changed. See this FAQ.

cppcheck indicates resource leak in APKOpen.cpp

RESOLVED FIXED in mozilla9

Status

()

Core
Widget: Android
RESOLVED FIXED
6 years ago
6 years ago

People

(Reporter: David Volgyes, Assigned: Atul Aggarwal)

Tracking

(Blocks: 1 bug)

Trunk
mozilla9
ARM
Android
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [good first bug] [mentor=jdm])

Attachments

(1 attachment)

(Reporter)

Description

6 years ago
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20100101 Firefox/6.0
Build ID: 20110812233755

Steps to reproduce:

cppcheck found some error in other-licenses/android/APKOpen.cpp.



Actual results:

The warnings:
[other-licenses/android/APKOpen.cpp:293]: (error) Resource leak: fd
[other-licenses/android/APKOpen.cpp:512]: (error) Resource leak: fd

1st, 2nd: There are several exit point in APKOpen, where a file is open, and it is not closed at exit. 



Expected results:

You should close the file before the exit points.
Sometimes it is tricky, because the file is memory mapped, so first you have to unmap, and close the file after the unmap.

As far as I see this is upstream code, so maybe someone should propagate the error-report to the upstream code.
Component: General → Widget: Android
OS: Linux → Android
Product: Firefox → Core
QA Contact: general → android
Hardware: x86_64 → ARM

Updated

6 years ago
Blocks: 679417

Comment 1

6 years ago
APKOpen.cpp is all mozilla code.

Comment 2

6 years ago
If that's the case, then some enterprising person should be able to fix this up without much fuss. I think a class that closes the file handle in its destructor would be the best way to solve the problem. See http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/readstrings/readstrings.cpp#60 for an example.
Whiteboard: [good first bug] [mentor=jdm]

Updated

6 years ago
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 3

6 years ago
(In reply to Josh Matthews [:jdm] from comment #2)
> If that's the case, then some enterprising person should be able to fix this
> up without much fuss. I think a class that closes the file handle in its
> destructor would be the best way to solve the problem. See
> http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/readstrings/
> readstrings.cpp#60 for an example.

In the case of APKOpen.cpp, we aim to use as few C++ features as possible. IIRC it's c++ due to linking issues.

Comment 4

6 years ago
In that case ignore comment 2. Let's just add fclose calls to every exit point in the function.
(Assignee)

Comment 5

6 years ago
Created attachment 556394 [details] [diff] [review]
v1 patch for close(fd)
Attachment #556394 - Flags: review?(josh)

Updated

6 years ago
Attachment #556394 - Flags: review?(mwu)

Comment 6

6 years ago
mwu should review all changes to this file

Updated

6 years ago
Attachment #556394 - Flags: review?(josh)

Comment 7

6 years ago
Comment on attachment 556394 [details] [diff] [review]
v1 patch for close(fd)

Heh.
Attachment #556394 - Flags: review?(mwu) → review+
Assignee: nobody → atulagrwl
Keywords: checkin-needed
In my queue :-)
Status: NEW → ASSIGNED
Keywords: checkin-needed
Quick sanity check:
http://tbpl.allizom.org/?tree=Try&usebuildbot=1&rev=46750bfed1e1
...then onto inbound afterwards :-)
http://hg.mozilla.org/integration/mozilla-inbound/rev/1cd727227440
Target Milestone: --- → mozilla9
http://hg.mozilla.org/mozilla-central/rev/1cd727227440
Status: ASSIGNED → RESOLVED
Last Resolved: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.