nostrdb/blocks: add ndb_blocks_free

In some situations we will need to have owned note blocks. For
example, when we try to fetch note blocks from the database and it's not
there yet. We will need to parse the content on the spot and return an
owned copy, since it will not be immediately available in the database.

Add a new flag field to note blocks that lets us know if it's owned by
malloc or nostrdb.

We the add a free function that checks this flag and frees the object if
its set. If it is not set then it doesn nothing because it likely came
from the database.

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2023-12-30 06:30:32 -08:00
committed by Daniel D’Aquino
parent c831976078
commit f2795aa71c
4 changed files with 14 additions and 1 deletions

View File

@@ -536,6 +536,7 @@ int ndb_parse_content(unsigned char *buf, int buf_size,
parser.blocks->words = 0;
parser.blocks->num_blocks = 0;
parser.blocks->blocks_size = 0;
parser.blocks->flags = 0;
blocks_start = start = parser.content.p;
while (parser.content.p < parser.content.end) {