[libbluray-devel] Fixed leaks
hpi1
git at videolan.org
Fri May 6 10:59:08 CEST 2011
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Fri May 6 11:53:43 2011 +0300| [c003a5defb0ce20785232dba566f73467fa41d5e] | committer: hpi1
Fixed leaks
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c003a5defb0ce20785232dba566f73467fa41d5e
---
src/libbluray/bdj/bdjo_parser.c | 31 +++++++++++++++++++------------
1 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/src/libbluray/bdj/bdjo_parser.c b/src/libbluray/bdj/bdjo_parser.c
index 94effb9..052e9e2 100644
--- a/src/libbluray/bdj/bdjo_parser.c
+++ b/src/libbluray/bdj/bdjo_parser.c
@@ -395,7 +395,9 @@ static jobject _parse_bdjo(JNIEnv* env, BITBUFFER* buf)
jobject bdjo_read(JNIEnv* env, const char* file)
{
+ jobject result = NULL;
BD_FILE_H *handle = file_open(file, "rb");
+
if (handle == NULL) {
BD_DEBUG(DBG_BDJ | DBG_CRIT, "Failed to open bdjo file (%s)\n", file);
return NULL;
@@ -404,26 +406,31 @@ jobject bdjo_read(JNIEnv* env, const char* file)
file_seek(handle, 0, SEEK_END);
int64_t length = file_tell(handle);
- if (length > 0) {
+ if (length <= 0) {
+ BD_DEBUG(DBG_BDJ | DBG_CRIT, "Error reading %s\n", file);
+
+ } else {
file_seek(handle, 0, SEEK_SET);
uint8_t *data = malloc(length);
int64_t size_read = file_read(handle, data, length);
+
if (size_read < length) {
- free(data);
- return NULL;
- }
+ BD_DEBUG(DBG_BDJ | DBG_CRIT, "Error reading %s\n", file);
- BITBUFFER* buf = malloc(sizeof(BITBUFFER));
- bb_init(buf, data, length);
+ } else {
+ BITBUFFER *buf = malloc(sizeof(BITBUFFER));
+ bb_init(buf, data, length);
- jobject result = _parse_bdjo(env, buf);
+ result = _parse_bdjo(env, buf);
- free(buf);
- file_close(handle);
+ free(buf);
+ }
- return result;
- } else {
- return NULL;
+ free(data);
}
+
+ file_close(handle);
+
+ return result;
}
More information about the libbluray-devel
mailing list