From 7a77958ba20c2b344be5e66e69e2f212a4bbf6b3 Mon Sep 17 00:00:00 2001 From: Craig Barnes Date: Sat, 8 Aug 2020 20:34:30 +0100 Subject: Convert most dynamic allocations to use functions from xmalloc.h --- extract.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'extract.c') diff --git a/extract.c b/extract.c index 45dbee3f..49a37f14 100644 --- a/extract.c +++ b/extract.c @@ -20,6 +20,11 @@ struct extraction_context * extract_begin(enum selection_kind kind) { struct extraction_context *ctx = malloc(sizeof(*ctx)); + if (unlikely(ctx == NULL)) { + LOG_ERRNO("malloc() failed"); + return NULL; + } + *ctx = (struct extraction_context){ .selection_kind = kind, }; @@ -80,6 +85,11 @@ extract_finish(struct extraction_context *ctx, char **text, size_t *len) } *text = malloc(_len + 1); + if (unlikely(text == NULL)) { + LOG_ERRNO("malloc() failed"); + goto out; + } + wcstombs(*text, ctx->buf, _len + 1); if (len != NULL) -- cgit v1.3