@@ -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 ;
@@ -857,7 +855,7 @@ int Multipart::process_part_header(std::string *error, int offset) {
857855 }
858856
859857 new_value = std::string (data);
860- utils::string::chomp (& new_value);
858+ utils::string::chomp (new_value);
861859
862860 /* update the header value in the table */
863861 header_value = m_mpp->m_headers .at (
@@ -926,7 +924,7 @@ int Multipart::process_part_header(std::string *error, int offset) {
926924 i++;
927925 }
928926 header_value = std::string (data);
929- utils::string::chomp (& header_value);
927+ utils::string::chomp (header_value);
930928
931929 /* error if the name already exists */
932930 if (m_mpp->m_headers .count (header_name) > 0 ) {
@@ -1271,22 +1269,10 @@ int Multipart::multipart_complete(std::string *error) {
12711269
12721270
12731271int 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