summaryrefslogtreecommitdiff
path: root/xpcom
diff options
context:
space:
mode:
authorFranklinDM <mrmineshafter17@gmail.com>2022-11-20 17:29:32 +0800
committerFranklinDM <mrmineshafter17@gmail.com>2022-11-20 18:42:34 +0800
commit06bc499a0d0f8c14e28b993c924ae2e43e1ff7c3 (patch)
treedf516597db87148d5dbc00db0d72fdb878ca1a54 /xpcom
parentc127f58ef33bff7bbea7fb300bc858d9f8273aec (diff)
downloaduxp-06bc499a0d0f8c14e28b993c924ae2e43e1ff7c3.tar.gz
Issue #2027 - Use reserved stack space instead of heap allocation in nsLocalFile
This should resolve the build bustage associated with c127f58ef3. Based on https://bugzilla.mozilla.org/show_bug.cgi?id=1371279
Diffstat (limited to 'xpcom')
-rw-r--r--xpcom/io/nsLocalFileUnix.cpp24
1 files changed, 9 insertions, 15 deletions
diff --git a/xpcom/io/nsLocalFileUnix.cpp b/xpcom/io/nsLocalFileUnix.cpp
index a092d4c26a..33c6b6bfaf 100644
--- a/xpcom/io/nsLocalFileUnix.cpp
+++ b/xpcom/io/nsLocalFileUnix.cpp
@@ -1715,14 +1715,13 @@ nsLocalFile::GetNativeTarget(nsACString& aResult)
}
int32_t size = (int32_t)symStat.st_size;
- char* target = (char*)moz_xmalloc(size + 1);
- if (!target) {
+ nsAutoCString target;
+ if (!target.SetLength(size, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
ssize_t written = readlink(mPath.get(), target.BeginWriting(), size_t(size));
if (written < 0) {
- free(target);
return NSRESULT_FOR_ERRNO();
}
// Target might have changed since the lstat call, or lstat might lie, see bug
@@ -1743,7 +1742,7 @@ nsLocalFile::GetNativeTarget(nsACString& aResult)
if (NS_FAILED(rv = self->GetParent(getter_AddRefs(parent)))) {
break;
}
- if (NS_FAILED(rv = parent->AppendRelativeNativePath(nsDependentCString(target)))) {
+ if (NS_FAILED(rv = parent->AppendRelativeNativePath(target))) {
break;
}
if (NS_FAILED(rv = parent->GetNativePath(aResult))) {
@@ -1768,17 +1767,14 @@ nsLocalFile::GetNativeTarget(nsACString& aResult)
}
int32_t newSize = (int32_t)symStat.st_size;
- if (newSize > size) {
- char* newTarget = (char*)moz_xrealloc(target, newSize + 1);
- if (!newTarget) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
- }
- target = newTarget;
- size = newSize;
+ size = newSize;
+ nsAutoCString newTarget;
+ if (!newTarget.SetLength(size, mozilla::fallible)) {
+ rv = NS_ERROR_OUT_OF_MEMORY;
+ break;
}
- ssize_t linkLen = readlink(flatRetval.get(), target, size);
+ ssize_t linkLen = readlink(flatRetval.get(), newTarget.BeginWriting(), size);
if (linkLen == -1) {
rv = NSRESULT_FOR_ERRNO();
break;
@@ -1789,8 +1785,6 @@ nsLocalFile::GetNativeTarget(nsACString& aResult)
target = newTarget;
}
- free(target);
-
if (NS_FAILED(rv)) {
aResult.Truncate();
}