Dynamically allocate session ID string

This commit is contained in:
Cameron Gutman
2020-04-29 20:12:19 -07:00
parent 7d0458a16b
commit fcabfc37ad
+15 -6
View File
@@ -7,7 +7,7 @@
static int currentSeqNumber; static int currentSeqNumber;
static char rtspTargetUrl[256]; static char rtspTargetUrl[256];
static char sessionIdString[16]; static char* sessionIdString;
static int hasSessionId; static int hasSessionId;
static int rtspClientVersion; static int rtspClientVersion;
static char urlAddr[URLSAFESTRING_LEN]; static char urlAddr[URLSAFESTRING_LEN];
@@ -35,7 +35,7 @@ static POPTION_ITEM createOptionItem(char* option, char* content)
return NULL; return NULL;
} }
item->option = malloc(strlen(option) + 1); item->option = strdup(option);
if (item->option == NULL) { if (item->option == NULL) {
free(item); free(item);
return NULL; return NULL;
@@ -43,7 +43,7 @@ static POPTION_ITEM createOptionItem(char* option, char* content)
strcpy(item->option, option); strcpy(item->option, option);
item->content = malloc(strlen(content) + 1); item->content = strdup(content);
if (item->content == NULL) { if (item->content == NULL) {
free(item->option); free(item->option);
free(item); free(item);
@@ -771,7 +771,7 @@ int performRtspHandshake(void) {
sessionId = getOptionContent(response.options, "Session"); sessionId = getOptionContent(response.options, "Session");
if (sessionId == NULL) { if (sessionId == NULL) {
Limelog("RTSP SETUP streamid=audio is missing session attribute"); Limelog("RTSP SETUP streamid=audio is missing session attribute\n");
ret = -1; ret = -1;
goto Exit; goto Exit;
} }
@@ -781,9 +781,13 @@ int performRtspHandshake(void) {
// resolves any 454 session not found errors on // resolves any 454 session not found errors on
// standard RTSP server implementations. // standard RTSP server implementations.
// (i.e - sessionId = "DEADBEEFCAFE;timeout = 90") // (i.e - sessionId = "DEADBEEFCAFE;timeout = 90")
sessionId = strtok(sessionId, ";"); sessionIdString = strdup(strtok(sessionId, ";"));
if (sessionIdString == NULL) {
Limelog("Failed to duplicate session ID string\n");
ret = -1;
goto Exit;
}
strcpy(sessionIdString, sessionId);
hasSessionId = 1; hasSessionId = 1;
freeMessage(&response); freeMessage(&response);
@@ -907,5 +911,10 @@ Exit:
} }
} }
if (sessionIdString != NULL) {
free(sessionIdString);
sessionIdString = NULL;
}
return ret; return ret;
} }