Closed
Bug 213692
Opened 21 years ago
Closed 16 years ago
PREF_CopyCharPref uses the wrong allocator
Categories
(Core :: Preferences: Backend, defect)
Core
Preferences: Backend
Tracking
()
RESOLVED
FIXED
People
(Reporter: timeless, Assigned: neil)
Details
Attachments
(1 file, 2 obsolete files)
(deleted),
patch
|
timeless
:
review+
neil
:
superreview+
|
Details | Diff | Splinter Review |
242 // These functions are similar to the above "Get" version with the significant
243 // difference that the preference module will alloc the memory (e.g.
XP_STRDUP) and
244 // the caller will need to be responsible for freeing it...
245 // </font>
246 */
247 PrefResult PREF_CopyCharPref(const char *pref, char ** return_buf, PRBool
isDefault);
679 PREF_CopyCharPref(const char *pref_name, char ** return_buffer, PRBool
get_default)
680 {
...
698 *return_buffer = PL_strdup(stringVal);
....
703 }
*
Referenced (in 3 files total) in:
* modules/libpref/src/nsPrefBranch.cpp:
o View change log or Blame annotations line 212
o line 834
o line 945
Is the only consumer (Bug 213691 covers mozilla's bad paste job)
943 NS_IMETHODIMP nsPrefBranch::SecurityGetCharPref(const char *pref, char **
return_buf)
944 {
945 return _convertRes(PREF_CopyCharPref(getPrefName(pref), return_buf,
PR_FALSE));
946 }
Note that the caller is an xpcom method and its out param should use the xpcom
allocator which is not compatible w/ pl_strdupn
Assignee | ||
Comment 1•16 years ago
|
||
While I was looking, I also found:
* nsPrefService uses PR_Free on memory prefapi.cpp allocated with ToNewCString
* prefapi.cpp uses PR_Free/PR_FREEIF on memory allocated with PL_strdup
* prefapi.cpp uses PR_Free on memory allocated with malloc
In this last case I could have changed the allocator instead; for the other cases there is no compatible allocator for that particular deallocator.
Assignee: ccarlen → neil
Status: NEW → ASSIGNED
Attachment #368353 -
Flags: superreview?(benjamin)
Attachment #368353 -
Flags: review?(timeless)
Comment on attachment 368353 [details] [diff] [review]
Proposed patch
as a reminder, PL_strfree while being the correct pair to PL_strdup, is not null safe :)
Based on the way the code uses pointers, I don't think you can simply drop the null checks:
663 oldValue->stringVal = newValue.stringVal ? PL_strdup(newValue.stringVal) : NULL;
Attachment #368353 -
Flags: review?(timeless) → review+
Assignee | ||
Comment 3•16 years ago
|
||
Attachment #368774 -
Flags: superreview?(benjamin)
Attachment #368774 -
Flags: review?(timeless)
Updated•16 years ago
|
Attachment #368774 -
Flags: superreview?(benjamin) → superreview+
Updated•16 years ago
|
Attachment #368353 -
Flags: superreview?(benjamin)
Assignee | ||
Comment 4•16 years ago
|
||
Strangely missing from the previous attachment was the hunk that was actually trying to fix the bug as described...
Attachment #368353 -
Attachment is obsolete: true
Attachment #368774 -
Attachment is obsolete: true
Attachment #369638 -
Flags: superreview+
Attachment #369638 -
Flags: review?(timeless)
Attachment #368774 -
Flags: review?(timeless)
Attachment #369638 -
Flags: review?(timeless) → review+
Assignee | ||
Comment 5•16 years ago
|
||
Pushed changeset 0ee18978858a to mozilla-central.
Status: ASSIGNED → RESOLVED
Closed: 16 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•