Closed Bug 1246839 Opened 10 years ago Closed 10 years ago

Fix resource leaks from Coverity

Categories

(Firefox for Android Graveyard :: General, defect)

All
Android
defect
Not set
normal

Tracking

(firefox47 fixed)

RESOLVED FIXED
Firefox 47
Tracking Status
firefox47 --- fixed

People

(Reporter: mcomella, Assigned: mcomella)

References

Details

Attachments

(2 files, 2 obsolete files)

No description provided.
https://reviewboard.mozilla.org/r/34101/#review30797 https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ "A content provider is created when its hosting process is created, and remains around for as long as the process does, so there is no need to close the database -- it will get closed as part of the kernel cleaning up the process's resources when the process is killed." -- Dianne Hackborn
Comment on attachment 8717267 [details] MozReview Request: Bug 1246839 - Close Reader in ApkResources. r=margaret https://reviewboard.mozilla.org/r/34103/#review30799 ::: mobile/android/base/java/org/mozilla/gecko/BrowserApp.java:3279 (Diff revision 1) > + } catch (final IOException e) { /* Nothing to do here. */ } Just push this into the enclosing `catch`.
Attachment #8717267 - Flags: review+
Comment on attachment 8717268 [details] MozReview Request: Bug 1246839 - Close Reader in ApkResources. r=margaret https://reviewboard.mozilla.org/r/34105/#review30801
Attachment #8717268 - Flags: review+
https://reviewboard.mozilla.org/r/34107/#review30803 ::: mobile/android/base/java/org/mozilla/gecko/db/SharedBrowserDatabaseProvider.java:111 (Diff revision 1) > - final Cursor cursor = db.query(tableName, new String[] { CommonColumns._ID }, selection, null, null, null, null, limit); > + final Cursor cursor = db.query(tableName, new String[]{CommonColumns._ID}, selection, null, null, null, null, limit); Our style is still to keep whitespace in this situation. Makes things easier to read. ::: mobile/android/base/java/org/mozilla/gecko/db/SharedBrowserDatabaseProvider.java:121 (Diff revision 1) > + db.close(); Again, ContentProviders shouldn't close their database connections.
Attachment #8717266 - Flags: review?(margaret.leibovic)
Attachment #8717267 - Flags: review?(margaret.leibovic)
Attachment #8717268 - Flags: review?(margaret.leibovic)
Comment on attachment 8717269 [details] MozReview Request: Bug 1246839 - Close DB in SharedBrowserDatabaseProvider. r=margaret If you want to keep Coverity happy, you can implement ContentProvider.shutdown(), and shut down any open connections there. Note that shutdown is an API11+ method, and is ordinarily only called from tests. Do not call super.shutdown(), and try not to open a connection only to close it again!
Attachment #8717269 - Flags: review?(margaret.leibovic)
Status: NEW → ASSIGNED
https://reviewboard.mozilla.org/r/34103/#review30799 > Just push this into the enclosing `catch`. Pushing it into the enclosing catch would result in cleaner code but it's less safe for future changes and less obvious who might be throwing the Exception. I'm going to leave it the way it is.
(In reply to Richard Newman [:rnewman] from comment #9) > If you want to keep Coverity happy, you can implement > ContentProvider.shutdown(), and shut down any open connections there. The javadoc indicates this is really a test method. Changing our code with hacks to keep the static analyzer happy seems like a waste so I'll just ignore the issues in Coverity.
https://reviewboard.mozilla.org/r/34107/#review30803 > Our style is still to keep whitespace in this situation. Makes things easier to read. /me shakes fist at IntelliJ!
https://reviewboard.mozilla.org/r/34101/#review30797 After discussing this with Newman and reading some source code, this makes sense. Assuming from the above comment that the db gets cleaned up when the process is killed and the resources used by an open DB handle are negligble, the `SQLiteOpenHelper` that backs the CP will cache an open database connection and each time `getWriteableDatabase` or `getReadableDatabase` is called, the cached instance is returned. Thus, when `close` is called, the backing DB is called and all open handles are invalidated. Since there's no reference counting, there's no need to close each DB instance. This is why it makes sense for an application to access the DB through a CP – it doesn't have to manage opening/closing the DB resources itself, a process which typically can cause leaks. Instead, it relies on the lifecycle of the CP to manage the DB state. Since these handles are accessed in CPs, I agree that the closing calls are unnecessary. It's also worth mentioning that it's less efficient to close the DB each time because there is some work done to re-open it – might as well make it faster (and simplify the code!) by not closing the connections.
Comment on attachment 8717266 [details] MozReview Request: Bug 1246839 - Close FileOutputStream in BrowserApp. r=margaret Review request updated; see interdiff: https://reviewboard.mozilla.org/r/34101/diff/1-2/
Attachment #8717266 - Attachment description: MozReview Request: Bug 1246839 - Close DB in AbstractTransactionalProvider. r=margaret → MozReview Request: Bug 1246839 - Close FileOutputStream in BrowserApp. r=margaret
Attachment #8717266 - Flags: review?(margaret.leibovic)
Comment on attachment 8717267 [details] MozReview Request: Bug 1246839 - Close Reader in ApkResources. r=margaret Review request updated; see interdiff: https://reviewboard.mozilla.org/r/34103/diff/1-2/
Attachment #8717267 - Attachment description: MozReview Request: Bug 1246839 - Close FileOutputStream in BrowserApp. r=margaret → MozReview Request: Bug 1246839 - Close Reader in ApkResources. r=margaret
Attachment #8717267 - Flags: review?(margaret.leibovic)
Attachment #8717266 - Flags: review?(margaret.leibovic)
Attachment #8717267 - Flags: review?(margaret.leibovic)
Comment on attachment 8717266 [details] MozReview Request: Bug 1246839 - Close FileOutputStream in BrowserApp. r=margaret Newman already r+'d this one.
Attachment #8717266 - Flags: review+
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 47
You should make a post to mobile-firefox-dev about Coverity. Maybe I missed a memo, but I don't have context around these changes.
Flags: needinfo?(michael.l.comella)
(In reply to :Margaret Leibovic from comment #19) > You should make a post to mobile-firefox-dev about Coverity. Maybe I missed > a memo, but I don't have context around these changes. afaict, you have to be a member of our Coverity project in order to see the defects which may or may not be available to the community. I posted internally, but if someone wants to do more research about how open it is, we could forward that to the larger group.
Flags: needinfo?(michael.l.comella)
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: