PORT_Strdup and PORT_Free do not use the same memory allocator

RESOLVED FIXED in 3.5

Status

P1
normal
RESOLVED FIXED
17 years ago
17 years ago

People

(Reporter: wtc, Assigned: wtc)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Assignee)

Description

17 years ago
A string returned by PORT_Strdup should be freed by PORT_Free.
However, right now PORT_Strdup is a macro that expands to
strdup, which uses libc's memory allocator, and PORT_Free calls
PR_Free, which uses NSPR's memory allocator.  They are not
matched.

There are two ways to fix this.

1. Define PORT_Strdup as a macro that expands to PL_strdup,
which uses NSPR's memory allocator.

2. Define PORT_Strdup as a function that calls PR_Malloc.

Which one do you like?
(Assignee)

Updated

17 years ago
Priority: -- → P1
Target Milestone: --- → 3.4.1
Version: 3.4 → 3.2

Comment 1

17 years ago
I like 1. If PL_strdup is already implemented and uses the allocator we want,
there is no need to have one more implementation. We should just map to it.

(Assignee)

Comment 2

17 years ago
Created attachment 74238 [details] [diff] [review]
Solution 1: define PORT_Strdup as PL_strdup
I vote yes for solution 1.
(Assignee)

Updated

17 years ago
Status: NEW → ASSIGNED
Target Milestone: 3.4.1 → 3.4

Comment 4

17 years ago
Comment on attachment 74238 [details] [diff] [review]
Solution 1: define PORT_Strdup as PL_strdup

I second the motion.
Attachment #74238 - Flags: review+
(Assignee)

Comment 5

17 years ago
Fix checked in.
Status: ASSIGNED → RESOLVED
Last Resolved: 17 years ago
Resolution: --- → FIXED
(Assignee)

Updated

17 years ago
Blocks: 131513
(Assignee)

Comment 6

17 years ago
I found that we are supposed to call PL_strfree() to free
the strings returned by PL_strdup(), and in the current
version of NSPR, PL_strdup() calls malloc(), not PR_Malloc(),
to allocate memory, and PL_strfree() simply calls free().

So if we define PORT_Strdup as PL_strdup, we still can't
use PORT_Free to free the strings returned by PORT_Strdup.
With the current implementation of PL_strdup, the fix I
checked in did not cause PORT_Strdup to use NSPR's memory
allocator.

I am reopening the bug.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Target Milestone: 3.4 → 3.4.1
(Assignee)

Comment 7

17 years ago
Created attachment 78040 [details] [diff] [review]
Solution 2: define PORT_Strdup as a function that calls PORT_Alloc

1. Now that PORT_Strdup is a function, it needs to be
exported from nss.def.

2. I took the opportunity to fix two other problems.
- The type of the 'str' argument to PORT_ArenaStrdup
  is 'char *'.	It should be 'const char *'.
- strrchr is a standard C library function, so we
  don't need to use PL_strrchr.
(Assignee)

Comment 8

17 years ago
Changed the QA contact to Bishakha.
QA Contact: sonja.mirtitsch → bishakhabanerjee
(Assignee)

Comment 9

17 years ago
I checked in Solution 2 into the tip of NSS.
Set target milestone to NSS 3.5.
Status: REOPENED → RESOLVED
Last Resolved: 17 years ago17 years ago
Resolution: --- → FIXED
Target Milestone: 3.4.1 → 3.5
You need to log in before you can comment on or make changes to this bug.