@@ -65,10 +65,7 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
6565 md5_context_t _ctx;
6666#endif
6767 uint8_t i;
68- uint8_t * _buf = (uint8_t *)malloc (16 );
69- if (_buf == NULL )
70- return false ;
71- memset (_buf, 0x00 , 16 );
68+ uint8_t * _buf[16 ] = {0 };
7269#ifdef ESP32
7370 mbedtls_md5_init (&_ctx);
7471 mbedtls_md5_starts_ret (&_ctx);
@@ -82,7 +79,6 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
8279 for (i = 0 ; i < 16 ; i++) {
8380 sprintf (output + (i * 2 ), " %02x" , _buf[i]);
8481 }
85- free (_buf);
8682 return true ;
8783}
8884
@@ -92,38 +88,35 @@ static String genRandomMD5(){
9288#else
9389 uint32_t r = rand ();
9490#endif
95- char * out = ( char *) malloc ( 33 ) ;
91+ char * out[ 33 ] ;
9692 if (out == NULL || !getMD5 ((uint8_t *)(&r), 4 , out))
9793 return " " ;
9894 String res = String (out);
99- free (out);
10095 return res;
10196}
10297
10398static String stringMD5 (const String& in){
104- char * out = ( char *) malloc ( 33 ) ;
105- if (out == NULL || !getMD5 ((uint8_t *)(in.c_str ()), in.length (), out))
99+ char * out[ 33 ] ;
100+ if (!getMD5 ((uint8_t *)(in.c_str ()), in.length (), out))
106101 return " " ;
107102 String res = String (out);
108- free (out);
109103 return res;
110104}
111105
112106String generateDigestHash (const char * username, const char * password, const char * realm){
113107 if (username == NULL || password == NULL || realm == NULL ){
114108 return " " ;
115109 }
116- char * out = ( char *) malloc ( 33 ) ;
110+ char * out[ 33 ] ;
117111 String res = String (username);
118112 res.concat (" :" );
119113 res.concat (realm);
120114 res.concat (" :" );
121115 String in = res;
122116 in.concat (password);
123- if (out == NULL || !getMD5 ((uint8_t *)(in.c_str ()), in.length (), out))
117+ if (!getMD5 ((uint8_t *)(in.c_str ()), in.length (), out))
124118 return " " ;
125119 res.concat (out);
126- free (out);
127120 return res;
128121}
129122
0 commit comments