Skip to content

Commit aa8cb4a

Browse files
committed
More resource leaks. One zh translation error.
1 parent f6ae910 commit aa8cb4a

6 files changed

Lines changed: 23 additions & 4 deletions

File tree

app/res/values-zh/strings.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<string name="title_edit_transaction">修改交易</string>
4747
<string name="label_transaction_description">备注</string>
4848
<string name="menu_move">移动</string>
49-
<string name="title_selected">%1$d 已删除</string>
49+
<string name="title_selected">%1$d 已选中</string>
5050
<string name="label_transactions_total">合计:</string>
5151
<string name="label_export_destination">导出到</string>
5252
<string name="title_export_dialog">导出交易资料</string>
@@ -352,7 +352,6 @@
352352
<string name="label_default_transfer_account">默认的转账帐户</string>
353353
<string name="label_account_color_and_type">科目颜色和类型</string>
354354
<plurals name="label_sub_accounts">
355-
<item quantity="one">%d 子科目</item>
356355
<item quantity="other">%d 子科目</item>
357356
</plurals>
358357
<string-array name="account_type_entry_values">

app/src/org/gnucash/android/db/AccountsDbAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public boolean destructiveDeleteAccount(long rowId){
165165
result &= mTransactionsAdapter.deleteRecord(id);
166166
}
167167
result &= deleteRecord(DatabaseHelper.ACCOUNTS_TABLE_NAME, rowId);
168+
c.close();
168169
return result;
169170
}
170171

app/src/org/gnucash/android/export/ExporterTask.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ protected void onPostExecute(Boolean exportResult) {
169169
android.support.v4.app.FragmentManager fragmentManager = ((FragmentActivity)mContext).getSupportFragmentManager();
170170
Fragment currentFragment = fragmentManager
171171
.findFragmentByTag(AccountsActivity.FRAGMENT_ACCOUNTS_LIST);
172+
172173
TransactionsDeleteConfirmationDialogFragment alertFragment =
173174
TransactionsDeleteConfirmationDialogFragment.newInstance(R.string.title_confirm_delete, 0);
174175
alertFragment.setTargetFragment(currentFragment, 0);
@@ -218,6 +219,7 @@ private void writeQifExternalStorage(String qif) throws IOException {
218219
writer.write(qif);
219220

220221
writer.flush();
222+
writer.close();
221223
}
222224

223225
/**

app/src/org/gnucash/android/export/ofx/OfxExporter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public OfxExporter(Context context, boolean exportAll) {
5959
mAccountsList = exportAll ? dbAdapter.getAllAccounts() : dbAdapter.getExportableAccounts();
6060
mExportAll = exportAll;
6161
mContext = context;
62+
dbAdapter.close();
6263
}
6364

6465
/**

app/src/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public class AccountFormFragment extends SherlockFragment {
8080
* Accounts database adapter
8181
*/
8282
private AccountsDbAdapter mAccountsDbAdapter;
83+
84+
/**
85+
* Whether the AccountsDbAdapter is created inside this class.
86+
* If so, it should be also closed by this class
87+
*/
88+
private boolean mReleaseDbAdapter = false;
8389

8490
/**
8591
* List of all currency codes (ISO 4217) supported by the app
@@ -191,6 +197,7 @@ public AccountFormFragment() {
191197
static public AccountFormFragment newInstance(AccountsDbAdapter dbAdapter){
192198
AccountFormFragment f = new AccountFormFragment();
193199
f.mAccountsDbAdapter = dbAdapter;
200+
f.mReleaseDbAdapter = false;
194201
return f;
195202
}
196203

@@ -199,6 +206,7 @@ public void onCreate(Bundle savedInstanceState) {
199206
super.onCreate(savedInstanceState);
200207
setHasOptionsMenu(true);
201208
if (mAccountsDbAdapter == null){
209+
mReleaseDbAdapter = true;
202210
mAccountsDbAdapter = new AccountsDbAdapter(getSherlockActivity());
203211
}
204212

@@ -660,8 +668,11 @@ public void onDestroy() {
660668
super.onDestroyView();
661669
if (mParentAccountCursor != null)
662670
mParentAccountCursor.close();
663-
//do not close the database adapter. We got it from the activity,
664-
//the activity will take care of it.
671+
// The mAccountsDbAdapter should only be closed when it is not passed in
672+
// by other Activities.
673+
if (mReleaseDbAdapter == true && mAccountsDbAdapter != null) {
674+
mAccountsDbAdapter.close();
675+
}
665676
}
666677

667678
private void saveAccount() {

app/src/org/gnucash/android/ui/transaction/TransactionFormFragment.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ private void updateTransferAccountsList(){
420420
+ "' AND " + DatabaseHelper.KEY_PLACEHOLDER + " = 0"
421421
+ ")";
422422

423+
if (mCursor != null) {
424+
mCursor.close();
425+
}
423426
mCursor = mAccountsDbAdapter.fetchAccountsOrderedByFullName(conditions);
424427

425428
mCursorAdapter = new QualifiedAccountNameCursorAdapter(getActivity(),
@@ -543,6 +546,8 @@ public void onAccountChanged(long newAccountId){
543546
}
544547

545548
updateTransferAccountsList();
549+
550+
accountsDbAdapter.close();
546551
}
547552

548553
/**

0 commit comments

Comments
 (0)