Closed
Bug 1159081
Opened 10 years ago
Closed 10 years ago
Bad PR_SetEnv usage for Gonk
Categories
(Toolkit :: General, defect)
Toolkit
General
Tracking
()
RESOLVED
FIXED
mozilla40
| Tracking | Status | |
|---|---|---|
| firefox40 | --- | fixed |
People
(Reporter: bbondy, Assigned: ehsan.akhgari)
References
Details
Attachments
(1 file)
|
1.44 KB,
patch
|
robert.strong.bugs
:
review+
dhylands
:
review+
|
Details | Diff | Splinter Review |
I think the PR_SetEnv usage for this Gonk related code is wrong:
https://dxr.mozilla.org/mozilla-central/source/toolkit/xre/nsUpdateDriver.cpp#872
> nsPrintfCString prioEnv("MOZ_UPDATER_PRIO=%d/%d/%d/%d",
> prioVal, oomScoreAdj, ioprioClass, ioprioLevel);
> PR_SetEnv(prioEnv.get());
From the PR_SetEnv documentation it says that the buffer passed can be used directly (the value is not copied in somewhere else) and so should not be stack allocated. I think that once prioVal goes out of scope the memory referenced will be freed.
Comment 1•10 years ago
|
||
needinfo'ing Dave and Ehsan since this was added as part of bug 802423.
Comment 2•10 years ago
|
||
One could also use hal::SetProcessPriority() directly on the PID of the spawned task: http://hg.mozilla.org/mozilla-central/file/caf25344f73e/hal/Hal.h#l476
Bonus points if somebody adds optional I/O prioritization support to that function; we could use it in FxOS too.
| Assignee | ||
Comment 3•10 years ago
|
||
Yeah, PR_SetEnv is a very thin wrapper around putenv on Linux, which is the suckiest API on the planet. It seems like the prevalent pattern for these cases is to use ToNewCString() to copy the string into the heap and leak the buffer.
Assignee: nobody → ehsan
Flags: needinfo?(ehsan)
Flags: needinfo?(dhylands)
| Assignee | ||
Comment 4•10 years ago
|
||
Attachment #8598603 -
Flags: review?(robert.strong.bugs)
Comment 5•10 years ago
|
||
Comment on attachment 8598603 [details] [diff] [review]
Fix the PR_SetEnv usage for the MOZ_UPDATER_PRIO environment variable on gonk
Looks fine to me. Let's make sure that Dave is also ok with this just in case this causes issues for gonk.
Attachment #8598603 -
Flags: review?(dhylands)
Comment 6•10 years ago
|
||
It looks like technically this isn't an issue for gonk, but it is an issue for API correctness.
PR_SetEnv winds up calling putenv, which does a strdup of its argument:
https://android.googlesource.com/platform/bionic/+/ics-mr1-release/libc/stdlib/putenv.c
Updated•10 years ago
|
Attachment #8598603 -
Flags: review?(dhylands) → review+
Updated•10 years ago
|
Attachment #8598603 -
Flags: review?(robert.strong.bugs) → review+
Comment 8•10 years ago
|
||
Pushed to mozilla-inbound
https://hg.mozilla.org/integration/mozilla-inbound/rev/db13f4410450
Keywords: checkin-needed
Target Milestone: --- → mozilla40
You need to log in
before you can comment on or make changes to this bug.
Description
•