Closed Bug 245670 Opened 21 years ago Closed 21 years ago

nsEscapeHTML and co should use autosize allocation?

Categories

(Core :: XPCOM, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: BenB, Assigned: BenB)

Details

Followup to bug 245399: PRUnichar *resultBuffer = (PRUnichar *)nsMemory::Alloc(aSourceBufferLen*7*sizeof(PRUnichar) + sizeof(PRUnichar('\0'))); The 7 comes from the longest possible entity replacement. First, this is prone to bugs - I *almost* caused a small buffer overflow (probably remotely triggerably) here, because I didn't notice the hardcoding of the length (at first). Also, this allocates 14 bytes memory per (unicode) source character for the output string, although the vast majority needs only 2 bytes. This is not just temporary, but returned to the called for further use. I don't know, how long these strings are typically retained, but this may be a huge waste of memory, depending on how often and long it's used. <http://lxr.mozilla.org/seamonkey/search?string=nsEscapeHTML> says 'not often', though. Anyways, my suggestion is to use nsAutoString (or something like it) there, which allocates memory (using nsMemory) based on actual need, and adopt the buffer on return (so that it isn't |free|d).
Ah, not many callers, don't care.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.