Skip to content

Commit ed1f1ab

Browse files
committed
prevent memoryleaks
1 parent e7373ed commit ed1f1ab

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

src/Audio.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Created on: Oct 28.2018
55
*
6-
* Version 3.0.13zd
6+
* Version 3.0.13ze
77
* Updated on: Dec 30.2024
88
* Author: Wolle (schreibfaul1)
99
*
@@ -528,8 +528,8 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
528528
xSemaphoreTakeRecursive(mutex_playAudioData, 0.3 * configTICK_RATE_HZ);
529529

530530
// optional basic authorization
531-
authLen = strlen(user) + strlen(pwd);
532-
char authorization[base64_encode_expected_len(authLen + 1) + 1];
531+
if(user && pwd) authLen = strlen(user) + strlen(pwd);
532+
char authorization[base64_encode_expected_len(authLen + 1) + 1];
533533
authorization[0] = '\0';
534534
if(authLen > 0) {
535535
char toEncode[authLen + 4];
@@ -563,22 +563,6 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
563563
h_host[pos_colon] = '\0';
564564
}
565565

566-
// // optional basic authorization
567-
// if(strlen(user) > 0 && strlen(pwd) > 0) {
568-
// authLen = strlen(user) + strlen(pwd);
569-
// authorization = x_ps_calloc(base64_encode_expected_len(authLen + 1), 1);
570-
// if(!authorization) {AUDIO_INFO("out of memory"); stopSong(); goto exit;}
571-
// toEncode = x_ps_calloc(authLen + 4, 1);
572-
// if(!toEncode) {AUDIO_INFO("out of memory"); stopSong(); goto exit;}
573-
// strcpy(toEncode, user);
574-
// strcat(toEncode, ":");
575-
// strcat(toEncode, pwd);
576-
// b64encode((const char*)toEncode, strlen(toEncode), authorization);
577-
// }
578-
// else{
579-
// authorization = strdup("");
580-
// }
581-
582566
setDefaults();
583567
rqh = x_ps_calloc(lenHost + strlen(authorization) + 300, 1); // http request header
584568
if(!rqh) {AUDIO_INFO("out of memory"); stopSong(); goto exit;}
@@ -653,7 +637,6 @@ bool Audio::connecttohost(const char* host, const char* user, const char* pwd) {
653637
xSemaphoreGiveRecursive(mutex_playAudioData);
654638
x_ps_free(h_host);
655639
x_ps_free(rqh);
656-
// x_ps_free(authorization);
657640
x_ps_free(toEncode);
658641
return res;
659642
}
@@ -3809,7 +3792,8 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque
38093792
if(!strncmp(c_host, m_lastHost, pos_slash)) {
38103793
AUDIO_INFO("redirect to new extension at existing host \"%s\"", c_host);
38113794
if(m_playlistFormat == FORMAT_M3U8) {
3812-
strcpy(m_lastHost, c_host);
3795+
x_ps_free(m_lastHost);
3796+
m_lastHost = strdup(c_host);
38133797
m_f_m3u8data = true;
38143798
}
38153799
httpPrint(c_host);

0 commit comments

Comments
 (0)