diff options
author | Yang Tse <yangsita@gmail.com> | 2010-02-03 13:28:47 +0000 |
---|---|---|
committer | Yang Tse <yangsita@gmail.com> | 2010-02-03 13:28:47 +0000 |
commit | b77d0db59e989d68db6ae856cb225afdb882a3e3 (patch) | |
tree | 47a881e46bb71b8b6626e5ac96cae8a067e63c22 | |
parent | 3205ac35b0ef6587bf53d23e9a36d7fcb251d875 (diff) |
Fix OOM handling
-rw-r--r-- | lib/rtsp.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/rtsp.c b/lib/rtsp.c index efbdf5d7a..a63784eaa 100644 --- a/lib/rtsp.c +++ b/lib/rtsp.c @@ -183,7 +183,7 @@ CURLcode Curl_rtsp(struct connectdata *conn, bool *done) if(!data->state.proto.rtsp) { /* Only allocate this struct if we don't already have it! */ - rtsp = calloc(sizeof(struct RTSP), 1); + rtsp = calloc(1, sizeof(struct RTSP)); if(!rtsp) return CURLE_OUT_OF_MEMORY; data->state.proto.rtsp = rtsp; @@ -532,9 +532,14 @@ CURLcode Curl_rtsp_rtp_readwrite(struct SessionHandle *data, if(rtspc->rtp_buf) { /* There was some leftover data the last time. Merge buffers */ - rtspc->rtp_buf = realloc(rtspc->rtp_buf, rtspc->rtp_bufsize + *nread); - if(!rtspc->rtp_buf) + char *newptr = realloc(rtspc->rtp_buf, rtspc->rtp_bufsize + *nread); + if(!newptr) { + Curl_safefree(rtspc->rtp_buf); + rtspc->rtp_buf = NULL; + rtspc->rtp_bufsize = 0; return CURLE_OUT_OF_MEMORY; + } + rtspc->rtp_buf = newptr; memcpy(rtspc->rtp_buf + rtspc->rtp_bufsize, k->str, *nread); rtspc->rtp_bufsize += *nread; rtp = rtspc->rtp_buf; @@ -603,8 +608,12 @@ CURLcode Curl_rtsp_rtp_readwrite(struct SessionHandle *data, /* Store the incomplete RTP packet for a "rewind" */ scratch = malloc(rtp_dataleft); - if(!scratch) + if(!scratch) { + Curl_safefree(rtspc->rtp_buf); + rtspc->rtp_buf = NULL; + rtspc->rtp_bufsize = 0; return CURLE_OUT_OF_MEMORY; + } memcpy(scratch, rtp, rtp_dataleft); Curl_safefree(rtspc->rtp_buf); rtspc->rtp_buf = scratch; @@ -727,6 +736,8 @@ CURLcode Curl_rtsp_parseheader(struct connectdata *conn, /* Copy the id substring into a new buffer */ data->set.str[STRING_RTSP_SESSION_ID] = malloc(end - start + 1); + if(data->set.str[STRING_RTSP_SESSION_ID] == NULL) + return CURLE_OUT_OF_MEMORY; memcpy(data->set.str[STRING_RTSP_SESSION_ID], start, end - start); (data->set.str[STRING_RTSP_SESSION_ID])[end - start] = '\0'; } |