Skip to content

Commit 1534ee2

Browse files
committed
Removed unnecessary copies
1 parent f8dd09f commit 1534ee2

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

src/request_body_processor/multipart.cc

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,20 @@ void MultipartPartTmpFile::Open() {
7070

7171
localtime_r(&tt, &timeinfo);
7272

73-
char tstr[300] {};
74-
strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo);
73+
char tstr[17];
74+
strftime(tstr, std::size(tstr), "/%Y%m%d-%H%M%S", &timeinfo);
7575

7676
std::string path = m_transaction->m_rules->m_uploadDirectory.m_value;
7777
path = path + tstr + "-" + *m_transaction->m_id.get();
7878
path += "-file-XXXXXX";
7979

80-
char* tmp = strdup(path.c_str());
8180
#ifndef WIN32
82-
m_tmp_file_fd = mkstemp(tmp);
81+
m_tmp_file_fd = mkstemp(path.data());
8382
#else
84-
_mktemp_s(tmp, path.length()+1);
85-
m_tmp_file_fd = _open(tmp, _O_CREAT | _O_EXCL | _O_RDWR);
83+
_mktemp_s(path.data(), path.length()+1);
84+
m_tmp_file_fd = _open(path.c_str(), _O_CREAT | _O_EXCL | _O_RDWR);
8685
#endif
87-
m_tmp_file_name.assign(tmp);
88-
free(tmp);
86+
m_tmp_file_name = path;
8987
ms_dbg_a(m_transaction, 4, "MultipartPartTmpFile: Create filename= " + m_tmp_file_name);
9088

9189
int mode = m_transaction->m_rules->m_uploadFileMode.m_value;
@@ -1271,22 +1269,10 @@ int Multipart::multipart_complete(std::string *error) {
12711269

12721270

12731271
int Multipart::count_boundary_params(const std::string& str_header_value) {
1274-
std::string lower = utils::string::tolower(str_header_value);
1275-
const char *header_value = lower.c_str();
1276-
char *duplicate = NULL;
1277-
char *s = NULL;
12781272
int count = 0;
12791273

1280-
if (header_value == NULL) {
1281-
return -1;
1282-
}
1283-
1284-
duplicate = strdup(header_value);
1285-
if (duplicate == NULL) {
1286-
return -1;
1287-
}
1288-
1289-
s = duplicate;
1274+
const auto lower = utils::string::tolower(str_header_value);
1275+
const char *s = lower.c_str();
12901276
while ((s = strstr(s, "boundary")) != NULL) {
12911277
s += 8;
12921278

@@ -1295,7 +1281,6 @@ int Multipart::count_boundary_params(const std::string& str_header_value) {
12951281
}
12961282
}
12971283

1298-
free(duplicate);
12991284
return count;
13001285
}
13011286

0 commit comments

Comments
 (0)