Fix code analysis issues and a couple small memory leaks

This commit is contained in:
Cameron Gutman 2014-08-24 12:47:04 -07:00
parent 22f6027cfa
commit 51710ff18a
2 changed files with 11 additions and 6 deletions

View File

@ -1,19 +1,20 @@
#include "Limelight-internal.h" #include "Limelight-internal.h"
#include "Rtsp.h" #include "Rtsp.h"
#define RTSP_MAX_RESP_SIZE 16384
static SOCKET sock = INVALID_SOCKET; static SOCKET sock = INVALID_SOCKET;
static IP_ADDRESS remoteAddr; static IP_ADDRESS remoteAddr;
static int currentSeqNumber = 1; static int currentSeqNumber = 1;
static char rtspTargetUrl[256]; static char rtspTargetUrl[256];
static char sessionIdString[16]; static char sessionIdString[16];
static int hasSessionId = 0; static int hasSessionId = 0;
static char responseBuffer[RTSP_MAX_RESP_SIZE];
/* GFE 2.1.1 */ /* GFE 2.1.1 */
#define RTSP_CLIENT_VERSION 10 #define RTSP_CLIENT_VERSION 10
#define RTSP_CLIENT_VERSION_S "10" #define RTSP_CLIENT_VERSION_S "10"
#define RTSP_MAX_RESP_SIZE 16384
/* Create RTSP Option */ /* Create RTSP Option */
static POPTION_ITEM createOptionItem(char* option, char* content) static POPTION_ITEM createOptionItem(char* option, char* content)
{ {
@ -81,7 +82,6 @@ static int initializeRtspRequest(PRTSP_MESSAGE msg, char* command, char* target)
/* Returns 1 on success, 0 otherwise */ /* Returns 1 on success, 0 otherwise */
static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response) { static int transactRtspMessage(PRTSP_MESSAGE request, PRTSP_MESSAGE response) {
int err, ret = 0; int err, ret = 0;
char responseBuffer[RTSP_MAX_RESP_SIZE];
int offset; int offset;
PRTSP_MESSAGE responseMsg = NULL; PRTSP_MESSAGE responseMsg = NULL;
char* serializedMessage = NULL; char* serializedMessage = NULL;

View File

@ -28,7 +28,7 @@ static int getMessageLength(PRTSP_MESSAGE msg){
} }
/* Add length of response-specific strings */ /* Add length of response-specific strings */
else { else {
char *statusCodeStr = malloc(sizeof(int)); char statusCodeStr[16];
sprintf(statusCodeStr, "%d", msg->message.response.statusCode); sprintf(statusCodeStr, "%d", msg->message.response.statusCode);
count += strlen(statusCodeStr); count += strlen(statusCodeStr);
count += strlen(msg->message.response.statusString); count += strlen(msg->message.response.statusString);
@ -303,9 +303,14 @@ void freeOptionList(POPTION_ITEM optionsHead){
/* Serialize the message struct into a string containing the RTSP message */ /* Serialize the message struct into a string containing the RTSP message */
char *serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength){ char *serializeRtspMessage(PRTSP_MESSAGE msg, int *serializedLength){
int size = getMessageLength(msg); int size = getMessageLength(msg);
char *serializedMessage = malloc(size); char *serializedMessage;
POPTION_ITEM current = msg->options; POPTION_ITEM current = msg->options;
char *statusCodeStr = malloc(4); // 3 characeters + NUL char statusCodeStr[16];
serializedMessage = malloc(size);
if (serializedMessage == NULL) {
return NULL;
}
if (msg->type == TYPE_REQUEST){ if (msg->type == TYPE_REQUEST){
/* command [space] */ /* command [space] */