diff options
author | Tor Andersson <tor@ghostscript.com> | 2009-11-20 21:29:56 +0100 |
---|---|---|
committer | Tor Andersson <tor@ghostscript.com> | 2009-11-20 21:29:56 +0100 |
commit | a16d9e0c25ed986c57c521aa87d87f6c343218a7 (patch) | |
tree | 9b0a38819ce69b9f1f9a187504224411d2dd8074 /fitz/stm_open.c | |
parent | 549dbe8e5563f9a228c8de35f07d0108e3adf74c (diff) | |
download | mupdf-a16d9e0c25ed986c57c521aa87d87f6c343218a7.tar.xz |
Malloc cannot return null. Clean up streams and filters.
Diffstat (limited to 'fitz/stm_open.c')
-rw-r--r-- | fitz/stm_open.c | 60 |
1 files changed, 12 insertions, 48 deletions
diff --git a/fitz/stm_open.c b/fitz/stm_open.c index c1f73f48..0f9e94f8 100644 --- a/fitz/stm_open.c +++ b/fitz/stm_open.c @@ -11,8 +11,6 @@ newstm(int kind) fz_stream *stm; stm = fz_malloc(sizeof(fz_stream)); - if (!stm) - return nil; stm->refs = 1; stm->kind = kind; @@ -66,19 +64,11 @@ fz_dropstream(fz_stream *stm) fz_error fz_openrfile(fz_stream **stmp, char *path) { - fz_error error; fz_stream *stm; stm = newstm(FZ_SFILE); - if (!stm) - return fz_rethrow(-1, "out of memory: stream struct"); - error = fz_newbuffer(&stm->buffer, FZ_BUFSIZE); - if (error) - { - fz_free(stm); - return fz_rethrow(error, "cannot create buffer"); - } + stm->buffer = fz_newbuffer(FZ_BUFSIZE); stm->file = open(path, O_BINARY | O_RDONLY, 0666); if (stm->file < 0) @@ -92,63 +82,37 @@ fz_error fz_openrfile(fz_stream **stmp, char *path) return fz_okay; } -fz_error fz_openrfilter(fz_stream **stmp, fz_filter *flt, fz_stream *src) +fz_stream * fz_openrfilter(fz_filter *flt, fz_stream *src) { - fz_error error; fz_stream *stm; stm = newstm(FZ_SFILTER); - if (!stm) - return fz_rethrow(-1, "out of memory: stream struct"); - - error = fz_newbuffer(&stm->buffer, FZ_BUFSIZE); - if (error) - { - fz_free(stm); - return fz_rethrow(error, "cannot create buffer"); - } - + stm->buffer = fz_newbuffer(FZ_BUFSIZE); stm->chain = fz_keepstream(src); stm->filter = fz_keepfilter(flt); - *stmp = stm; - return fz_okay; + return stm; } -fz_error fz_openrbuffer(fz_stream **stmp, fz_buffer *buf) +fz_stream * fz_openrbuffer(fz_buffer *buf) { fz_stream *stm; stm = newstm(FZ_SBUFFER); - if (!stm) - return fz_rethrow(-1, "out of memory: stream struct"); - stm->buffer = fz_keepbuffer(buf); - stm->buffer->eof = 1; - *stmp = stm; - return fz_okay; + return stm; } -fz_error fz_openrmemory(fz_stream **stmp, unsigned char *mem, int len) +fz_stream * fz_openrmemory(unsigned char *mem, int len) { - fz_error error; fz_buffer *buf; - - error = fz_newbufferwithmemory(&buf, mem, len); - if (error) - return fz_rethrow(error, "cannot create memory buffer"); - - error = fz_openrbuffer(stmp, buf); - if (error) - { - fz_dropbuffer(buf); - return fz_rethrow(error, "cannot open memory buffer stream"); - } - + fz_stream *stm; + + buf = fz_newbufferwithmemory(mem, len); + stm = fz_openrbuffer(buf); fz_dropbuffer(buf); - return fz_okay; + return stm; } - |