From fac322b834bde76b8456e1379865b593c3bed5d8 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sat, 8 Feb 2014 14:26:38 +0100 Subject: [PATCH] isl_printer: save copy of prefix/suffix The original implementation would simply copy the pointer passed to isl_printer_set_prefix or isl_printer_set_suffix, which is unsafe since the caller could release the corresponding memory after calling these functions. Keep a copy of the strings instead. Signed-off-by: Sven Verdoolaege --- isl_printer.c | 8 ++++++-- isl_printer_private.h | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/isl_printer.c b/isl_printer.c index b75d97ce..213f6f8f 100644 --- a/isl_printer.c +++ b/isl_printer.c @@ -260,6 +260,8 @@ __isl_null isl_printer *isl_printer_free(__isl_take isl_printer *p) if (!p) return NULL; free(p->buf); + free(p->prefix); + free(p->suffix); isl_ctx_deref(p->ctx); free(p); @@ -322,7 +324,8 @@ __isl_give isl_printer *isl_printer_set_prefix(__isl_take isl_printer *p, if (!p) return NULL; - p->prefix = prefix; + free(p->prefix); + p->prefix = prefix ? strdup(prefix) : NULL; return p; } @@ -333,7 +336,8 @@ __isl_give isl_printer *isl_printer_set_suffix(__isl_take isl_printer *p, if (!p) return NULL; - p->suffix = suffix; + free(p->suffix); + p->suffix = suffix ? strdup(suffix) : NULL; return p; } diff --git a/isl_printer_private.h b/isl_printer_private.h index 9d76808c..47b3f27d 100644 --- a/isl_printer_private.h +++ b/isl_printer_private.h @@ -11,7 +11,7 @@ struct isl_printer { char *buf; int indent; int output_format; - const char *prefix; - const char *suffix; + char *prefix; + char *suffix; int width; }; -- 2.11.4.GIT