From leorize <leorize+oss@xxxxxxxxxxx>:
leorize has uploaded this change for review. (
https://review.haiku-os.org/c/haiku/+/3074 ;)
Change subject: DataRequest: Use ArrayDeleter to manage the temporary buffer
......................................................................
DataRequest: Use ArrayDeleter to manage the temporary buffer
This simplify the clean up code path and make sure that the temporary
buffer will always be freed on exit.
Change-Id: I70c1a25bfa66c4f4a96dd3d0af3765a67e305fb2
---
M src/kits/network/libnetapi/DataRequest.cpp
1 file changed, 5 insertions(+), 7 deletions(-)
git pull ssh://git.haiku-os.org:22/haiku refs/changes/74/3074/1
diff --git a/src/kits/network/libnetapi/DataRequest.cpp
b/src/kits/network/libnetapi/DataRequest.cpp
index 6afd33c..a9ece68 100644
--- a/src/kits/network/libnetapi/DataRequest.cpp
+++ b/src/kits/network/libnetapi/DataRequest.cpp
@@ -9,6 +9,7 @@
#include "DataRequest.h"
+#include <AutoDeleter.h>
#include <HttpAuthentication.h>
#include <mail_encoding.h>
#include <stdio.h>
@@ -88,6 +89,7 @@
}
+ ArrayDeleter<char> buffer;
if (isBase64) {
// Check that the base64 data is properly padded (we process
characters
// by groups of 4 and there must not be stray chars at the end
as
@@ -95,18 +97,17 @@
if (data.Length() & 3)
return B_BAD_DATA;
- char* buffer = new char[data.Length() * 3 / 4];
- payload = buffer;
+ buffer.SetTo(new char[data.Length() * 3 / 4]);
+ payload = buffer.Get();
// payload must be a const char* so we can assign
data.String() to
// it below, but decode_64 modifies buffer.
- length = decode_base64(buffer, data.String(), data.Length());
+ length = decode_base64(buffer.Get(), data.String(),
data.Length());
// There may be some padding at the end of the base64 stream.
This
// prevents us from computing the exact length we should get,
so allow
// for some error margin.
if (length > data.Length() * 3 / 4
|| length < data.Length() * 3 / 4 - 3) {
- delete[] buffer;
return B_BAD_DATA;
}
} else {
@@ -124,8 +125,5 @@
}
}
- if (isBase64)
- delete[] payload;
-
return B_OK;
}
--
To view, visit https://review.haiku-os.org/c/haiku/+/3074
To unsubscribe, or for help writing mail filters, visit
https://review.haiku-os.org/settings
Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I70c1a25bfa66c4f4a96dd3d0af3765a67e305fb2
Gerrit-Change-Number: 3074
Gerrit-PatchSet: 1
Gerrit-Owner: leorize <leorize+oss@xxxxxxxxxxx>
Gerrit-MessageType: newchange