From f018a7b3a0d82b44606f3afc928d218b9a7bdf55 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 8 Sep 2024 16:34:23 +0200 Subject: [PATCH] val: Don't decref null values --- flamingo/val.c | 4 ++++ questions.md | 2 ++ 2 files changed, 6 insertions(+) diff --git a/flamingo/val.c b/flamingo/val.c index 062878e..5263c75 100644 --- a/flamingo/val.c +++ b/flamingo/val.c @@ -87,6 +87,10 @@ static void val_free(flamingo_val_t* val) { } static flamingo_val_t* val_decref(flamingo_val_t* val) { + if (val == NULL) { + return NULL; + } + val->ref_count--; if (val->ref_count > 0) { diff --git a/questions.md b/questions.md index eba68dd..f3fb7c6 100644 --- a/questions.md +++ b/questions.md @@ -6,3 +6,5 @@ I'm keeping track of these so I don't forget why I did something a certain way a *Q:* Should I really be passing TSNode everywhere instead of TSNode*? It feels like this is prone to me being like "oh, well, the TSNode type is probably hiding a pointer if it's being used as an argument, so I don't have to worry about out-of-scope usage". *A:* Yes. Tree-sitter passes them as values, so be consistent with that. + +*Q:* Do gently detached scopes need to be freed or are they already?