projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tests: dereference of NULL pointer on allocation failure
[babeltrace.git]
/
lib
/
ref.c
diff --git
a/lib/ref.c
b/lib/ref.c
index 0ac1014c626a47940d78d1da8a5d6f6c53f88194..ac0580137a5ad959d25fbfa29b3a3dc0a7ffae19 100644
(file)
--- a/
lib/ref.c
+++ b/
lib/ref.c
@@
-27,20
+27,29
@@
#include <babeltrace/ref-internal.h>
#include <babeltrace/object-internal.h>
#include <babeltrace/ref-internal.h>
#include <babeltrace/object-internal.h>
-void
bt_get(void *obj
)
+void
*bt_get(void *ptr
)
{
{
- if (obj) {
- struct bt_object *base = obj;
+ struct bt_object *obj = ptr;
- bt_ref_get(&base->ref_count);
+ if (!obj) {
+ goto end;
}
}
+
+ if (obj->parent && bt_object_get_ref_count(obj) == 0) {
+ bt_get(obj->parent);
+ }
+ bt_ref_get(&obj->ref_count);
+end:
+ return obj;
}
}
-void bt_put(void *
obj
)
+void bt_put(void *
ptr
)
{
{
- if (obj) {
- struct bt_object *base = obj;
+ struct bt_object *obj = ptr;
- bt_ref_put(&base->ref_count);
+ if (!obj) {
+ return;
}
}
+
+ bt_ref_put(&obj->ref_count);
}
}
This page took
0.025414 seconds
and
4
git commands to generate.