Closed
Bug 86688
Opened 23 years ago
Closed 23 years ago
nsAutoConfig object is not destroyed after it is done.
Categories
(Core :: Preferences: Backend, defect)
Tracking
()
mozilla0.9.4
People
(Reporter: mitesh, Assigned: mitesh)
Details
Attachments
(6 files)
1.65 KB,
patch
|
Details | Diff | Splinter Review | |
1.69 KB,
patch
|
Details | Diff | Splinter Review | |
6.57 KB,
patch
|
Details | Diff | Splinter Review | |
1.59 KB,
patch
|
Details | Diff | Splinter Review | |
1.74 KB,
patch
|
Details | Diff | Splinter Review | |
1.87 KB,
patch
|
Details | Diff | Splinter Review |
nsAutoConfig object is not being destroyed even it finishes its task. This is because it is registering itself as an observer to the profile change event and it is not a weak reference. Profile manager stays alive till browser exits so it keeps a reference to nsAutoConfig till end. Actually, once the nsAutoConfig finished loading/executing autoconfig.jsc, it is no longer needed (unless it kicks of a timer routine). There are two solutions: - Declare it as a weak reference. The problem is that it gets deleted right away when it is created as a part of the nsAppStartupNotifier::Observe(). Because it is created on a stack and when method finishes it gets out of scope and without a reference it gets deleted. - Call a removeObserver() once you are done. Right now removeObserver() is called through destructor which is like catch22. Destructor will not be called without removeObserver() and vice-a-versa. Instead, write a separate method which will call removeObserver(). Once the refCnt reaches zero, Release() will be called on the object.
Comment 1•23 years ago
|
||
->rvelasco for qa [punt if you're not the right person!]
QA Contact: sairuh → rvelasco
Comment 2•23 years ago
|
||
If you wish to support nsWeakReference, you should be able to eliminate this by ADDREF'ing yourself on creation and RELEASE'ing yourself when you are "done". This would be essentially the same as calling "removeObserver" when you are "done" without supporting nsWeakReference. All things considered, it sounds like option 2 is less work...
Assignee | ||
Comment 4•23 years ago
|
||
Attaching a patch for review. Caling removeObserver once we are done with AutoConfig.
Status: NEW → ASSIGNED
Assignee | ||
Comment 5•23 years ago
|
||
Assignee | ||
Comment 6•23 years ago
|
||
Comment 7•23 years ago
|
||
Shouldn't you only be calling FinishAutoConfig() if you haven't started a callback timer?
Assignee | ||
Comment 8•23 years ago
|
||
It's ok to remove from the observer list even if the timer callback has started. It won't get released if the timer callback has started and that's what we want. Since the timer callback will initiate DownloadAutoConfig() through Notify() we don't need to be an observer to "profile-after-chage" topic anymore to get it started. It is required for the first time only. So I have put the FinishAutoConfig() in the first time only code. In fact, if you put it outside the if (first_time) block, it will fail to remove itself from the observerlist during the timer callback since it has already been removed once.
Comment 9•23 years ago
|
||
Of course...duh. For some reason I was equating removal from the observer list with immediate destruction. r=bnesse.
Assignee | ||
Comment 10•23 years ago
|
||
Assignee | ||
Comment 11•23 years ago
|
||
New pach with additional FinisAutoConfig() at the early exits from the DownloadAutoConfig() and Observe() in case of errors. We need to release the object when we exit out of the autoconfig in any case
Comment 12•23 years ago
|
||
Good catch on the error condition case, and my bad for not noticing this before, but... Wouldn't it just be much simpler to add the RemoveObserver code into the Observe() method, right after calling DownloadAutoCfg()? ;)
Assignee | ||
Comment 13•23 years ago
|
||
I think it's a very good suggestion. The new patch moves the removeObsever to Observe() itself.
Assignee | ||
Comment 14•23 years ago
|
||
Comment 15•23 years ago
|
||
Two things: First, the mPrefBranch = 0 in the destructor is not necessary. You have no circular reference issues with the prefBranch object so you don't need to do this. Second, you have changed the logic in Observe such that DownloadAutoCfg() now can get called with mCurrProfile being null if it fails to get the profile name. Previously you returned an error if this failed... I don't think this was your intention, though it appears that the code will deal with this situation. If this was your intention, you should add comments to make it clear.
Assignee | ||
Comment 16•23 years ago
|
||
Ok. I will remove the mPrefBranch = 0 from the destructor. Regarding, the profile name being NULL, I checked that the code will deal with the situation so I didn't return on error. I will put a comment there.
Assignee | ||
Comment 17•23 years ago
|
||
Comment 18•23 years ago
|
||
Oh crap... I forgot... please indent these lines under the if case before you check in... // setting the member variable to the current profile name mCurrProfile = NS_ConvertUCS2toUTF8(profileName); with that change. r=bnesse.
Assignee | ||
Comment 19•23 years ago
|
||
Adding Seth for super review
Comment 20•23 years ago
|
||
it seems to me that the reason you are continuing on after profile->GetCurrentProfile(getter_Copies(profileName)); fails (instead of returning immediately) is so that we'll hit the code that removes the observer. but you'll be returning NS_OK instead of NS_ERROR_*, assuming that do_GetService() and RemoveObserver() succeed. is that what you want?
Assignee | ||
Comment 21•23 years ago
|
||
That's right. I am not returning on error so that it will hit the remove observer code. It's fine to return NS_OK, even if profile->GetCurrentProfile() fails. Actually, the previous version was wrong in a sense that it was not calling DownloadAutoCfg() if the call to profile->GetCurrentProfile() fails. We want to go and download the autoconfig.jsc even if we don't get the profile name. Profile name is used as a backup if we run the browser without a default email address. Email address or profile name is used to pass as an parameter to the URL. If none of them is available, nothing will be added to the URL and the default case of the script will be used and that's exactly what we want. And of course, it would be good if we report an error saying that GetCurrentProfile() fails. Right now, we don't have a proper error reporting mechanism for all these preferences code. I will add a NS_WARNING("..") for the else clause of if (NS_SUCCEEDED(rv)) {}
Comment 22•23 years ago
|
||
sounds good. attach the final patch bnesse can do the final r= and I can do the final sr=
Assignee | ||
Comment 23•23 years ago
|
||
indentation didn't seem right in the prev patch beacuse I ignored the white space changes in the diffs. Here is the new patch. Line numbers is not very accurate since I already have another patch in the file.
Assignee | ||
Comment 24•23 years ago
|
||
Comment 25•23 years ago
|
||
Indentation also appears incorrect in this patch, but I verified with mitesh that it was done with ignore whitespace again. Looks correct in his source file. r=bnesse.
Assignee | ||
Updated•23 years ago
|
Target Milestone: --- → mozilla0.9.4
Comment 26•23 years ago
|
||
sr=sspitzer
Assignee | ||
Comment 27•23 years ago
|
||
Code checked in. Checking in modules/libpref/src/nsAutoConfig.cpp; /cvsroot/mozilla/modules/libpref/src/nsAutoConfig.cpp,v <-- nsAutoConfig.cpp new revision: 3.9; previous revision: 3.8 done
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Comment 28•23 years ago
|
||
Luke, please work with mitesh on how to verify this bug. This looks like backend autoconfig stuff.
Comment 29•23 years ago
|
||
This bug was removed because of bug 94349
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Comment 30•23 years ago
|
||
THis the duplicate, sorry about that mix up. *** This bug has been marked as a duplicate of 97182 ***
Status: REOPENED → RESOLVED
Closed: 23 years ago → 23 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•