Commit bd1e7086 authored by conrad's avatar conrad

liboggz: handle out of memory on return from internal functions...

liboggz: handle out of memory on return from internal functions oggz_stream_add(), oggz_comments_init() throughout


git-svn-id: http://svn.annodex.net/liboggz/trunk@3821 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 313293e7
......@@ -120,6 +120,7 @@ oggz_comment_get_vendor (OGGZ * oggz, long serialno);
* \retval 0 Success
* \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
* \note The vendor string should identify the library used to produce
* the stream, e.g. libvorbis 1.0 used "Xiph.Org libVorbis I 20020717".
* If copying a bitstream it should be the same as the source.
......@@ -190,6 +191,7 @@ oggz_comment_next_byname (OGGZ * oggz, long serialno,
* \retval 0 Success
* \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/
int
oggz_comment_add (OGGZ * oggz, long serialno, OggzComment * comment);
......@@ -203,6 +205,7 @@ oggz_comment_add (OGGZ * oggz, long serialno, OggzComment * comment);
* \retval 0 Success
* \retval OGGZ_ERR_BAD \a oggz is not a valid OGGZ* handle
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/
int
oggz_comment_add_byname (OGGZ * oggz, long serialno,
......
......@@ -94,6 +94,7 @@ typedef int (*OggzReadPacket) (OGGZ * oggz, ogg_packet * op, long serialno,
* logical bitstream in \a oggz.
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*
* \note Values of \a serialno other than -1 allows you to specify different
* callback functions for each logical bitstream.
......@@ -131,6 +132,7 @@ typedef int (*OggzReadPage) (OGGZ * oggz, const ogg_page * og,
* \retval 0 Success
* \retval OGGZ_ERR_BAD_OGGZ \a oggz does not refer to an existing OGGZ
* \retval OGGZ_ERR_INVALID Operation not suitable for this OGGZ
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*
* \note Values of \a serialno other than -1 allows you to specify different
* callback functions for each logical bitstream.
......@@ -156,6 +158,7 @@ int oggz_set_read_page (OGGZ * oggz, long serialno,
* returning OGGZ_STOP_OK
* \retval OGGZ_ERR_STOP_ERR Reading was stopped by a user callback
* returning OGGZ_STOP_ERR
* \retval OGGZ_ERR_OUT_OF_MEMORY Out of memory
*/
long oggz_read (OGGZ * oggz, long n);
......
......@@ -337,7 +337,10 @@ oggz_add_stream (OGGZ * oggz, long serialno)
ogg_stream_init (&stream->ogg_stream, (int)serialno);
oggz_comments_init (stream);
if (oggz_comments_init (stream) == -1) {
oggz_free (stream);
return NULL;
}
stream->content = OGGZ_CONTENT_UNKNOWN;
stream->numheaders = 3; /* Default to 3 headers for Ogg logical bitstreams */
......
......@@ -225,7 +225,10 @@ oggz_comment_set_vendor (OGGZ * oggz, long serialno, const char * vendor_string)
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
if (oggz->flags & OGGZ_WRITE) {
if (OGGZ_CONFIG_WRITE) {
......@@ -331,7 +334,10 @@ oggz_comment_add (OGGZ * oggz, long serialno, const OggzComment * comment)
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
if (oggz->flags & OGGZ_WRITE) {
if (OGGZ_CONFIG_WRITE) {
......@@ -362,7 +368,10 @@ oggz_comment_add_byname (OGGZ * oggz, long serialno,
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
if (oggz->flags & OGGZ_WRITE) {
if (OGGZ_CONFIG_WRITE) {
......@@ -477,6 +486,8 @@ oggz_comments_init (oggz_stream_t * stream)
{
stream->vendor = NULL;
stream->comments = oggz_vector_new ();
if (stream->comments == NULL) return -1;
oggz_vector_set_cmp (stream->comments, (OggzCmpFunc) oggz_comment_cmp, NULL);
return 0;
......
......@@ -122,6 +122,8 @@ oggz_set_read_callback (OGGZ * oggz, long serialno,
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL)
stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
stream->read_packet = read_packet;
stream->read_user_data = user_data;
......@@ -152,6 +154,8 @@ oggz_set_read_page (OGGZ * oggz, long serialno, OggzReadPage read_page,
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL)
stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
stream->read_page = read_page;
stream->read_page_user_data = user_data;
......@@ -341,7 +345,7 @@ oggz_read_sync (OGGZ * oggz)
/* new stream ... check bos etc. */
if ((stream = oggz_add_stream (oggz, serialno)) == NULL) {
/* error -- could not add stream */
return -7;
return OGGZ_ERR_OUT_OF_MEMORY;
}
}
os = &stream->ogg_stream;
......@@ -499,7 +503,7 @@ oggz_read_sync (OGGZ * oggz)
/* new stream ... check bos etc. */
if ((stream = oggz_add_stream (oggz, serialno)) == NULL) {
/* error -- could not add stream */
return -7;
return OGGZ_ERR_OUT_OF_MEMORY;
}
/* identify stream type */
......@@ -568,6 +572,8 @@ oggz_read (OGGZ * oggz, long n)
reader = &oggz->x.reader;
cb_ret = oggz_read_sync (oggz);
if (cb_ret == OGGZ_ERR_OUT_OF_MEMORY)
return cb_ret;
while (cb_ret != OGGZ_STOP_ERR && cb_ret != OGGZ_STOP_OK &&
bytes_read > 0 && remaining > 0) {
......@@ -585,6 +591,8 @@ oggz_read (OGGZ * oggz, long n)
nread += bytes_read;
cb_ret = oggz_read_sync (oggz);
if (cb_ret == OGGZ_ERR_OUT_OF_MEMORY)
return cb_ret;
}
}
......@@ -636,6 +644,8 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n)
reader = &oggz->x.reader;
cb_ret = oggz_read_sync (oggz);
if (cb_ret == OGGZ_ERR_OUT_OF_MEMORY)
return cb_ret;
while (cb_ret != OGGZ_STOP_ERR && cb_ret != OGGZ_STOP_OK &&
/* !oggz->eos && */ remaining > 0) {
......@@ -649,6 +659,8 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n)
nread += bytes;
cb_ret = oggz_read_sync (oggz);
if (cb_ret == OGGZ_ERR_OUT_OF_MEMORY)
return cb_ret;
}
if (cb_ret == OGGZ_STOP_ERR) oggz_purge (oggz);
......
......@@ -257,6 +257,8 @@ oggz_write_feed (OGGZ * oggz, ogg_packet * op, long serialno, int flush,
if (b_o_s || !strict || suffix) {
stream = oggz_add_stream (oggz, serialno);
if (stream == NULL)
return OGGZ_ERR_OUT_OF_MEMORY;
oggz_auto_identify_packet (oggz, op, serialno);
} else {
return OGGZ_ERR_BAD_SERIALNO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment