Closed Bug 1159081 Opened 10 years ago Closed 10 years ago

Bad PR_SetEnv usage for Gonk

Categories

(Toolkit :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla40
Tracking Status
firefox40 --- fixed

People

(Reporter: bbondy, Assigned: ehsan.akhgari)

References

Details

Attachments

(1 file)

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.
needinfo'ing Dave and Ehsan since this was added as part of bug 802423.
Blocks: 802423
Flags: needinfo?(ehsan)
Flags: needinfo?(dhylands)
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.
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)
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)
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
Attachment #8598603 - Flags: review?(dhylands) → review+
This doesn't need a try run.
Keywords: checkin-needed
Attachment #8598603 - Flags: review?(robert.strong.bugs) → review+
Keywords: checkin-needed
Target Milestone: --- → mozilla40
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: