[libbluray-devel] fixed leak when realloc fails

hpi1 git at videolan.org
Wed Feb 26 09:09:15 CET 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Sun Feb 23 14:15:34 2014 +0200| [b1e2fb9ecd3c24efb9d064b3bc927293ad80bb18] | committer: hpi1

fixed leak when realloc fails

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=b1e2fb9ecd3c24efb9d064b3bc927293ad80bb18
---

 src/libbluray/register.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/libbluray/register.c b/src/libbluray/register.c
index 77b3575..d3d462f 100644
--- a/src/libbluray/register.c
+++ b/src/libbluray/register.c
@@ -206,6 +206,7 @@ void bd_psr_unlock(BD_REGISTERS *p)
 void bd_psr_register_cb  (BD_REGISTERS *p, void (*callback)(void*,BD_PSR_EVENT*), void *cb_handle)
 {
     /* no duplicates ! */
+    PSR_CB_DATA *cb;
     unsigned i;
 
     bd_psr_lock(p);
@@ -218,14 +219,14 @@ void bd_psr_register_cb  (BD_REGISTERS *p, void (*callback)(void*,BD_PSR_EVENT*)
         }
     }
 
-    p->num_cb++;
-    p->cb = realloc(p->cb, p->num_cb * sizeof(PSR_CB_DATA));
-    if (p->cb) {
-        p->cb[p->num_cb - 1].cb     = callback;
-        p->cb[p->num_cb - 1].handle = cb_handle;
+    cb = realloc(p->cb, (p->num_cb + 1) * sizeof(PSR_CB_DATA));
+    if (cb) {
+        p->cb = cb;
+        p->cb[p->num_cb].cb     = callback;
+        p->cb[p->num_cb].handle = cb_handle;
+        p->num_cb++;
     } else {
         BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_psr_register_cb(): realloc failed\n");
-        p->num_cb = 0;
     }
 
     bd_psr_unlock(p);



More information about the libbluray-devel mailing list