chiark / gitweb /
disorder.h: more consistent approach to function attributes
[disorder] / lib / asprintf.c
index da37319012c19f5f6a85a9c8f0f7a5577f280d48..44be7898ae02cde9a80758b16a821324b18a6cae 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder
- * Copyright (C) 2004-2008 Richard Kettlewell
+ * Copyright (C) 2004-2009 Richard Kettlewell
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <errno.h>
 
 #include "printf.h"
+#include "log.h"
 #include "sink.h"
 #include "mem.h"
 #include "vector.h"
-#include "log.h"
 
 /** @brief vasprintf() workalike without encoding errors
  *
 int byte_vasprintf(char **ptrp,
                   const char *fmt,
                   va_list ap) {
+  struct sink *s;
   struct dynstr d;
   int n;
 
   dynstr_init(&d);
-  if((n = byte_vsinkprintf(sink_dynstr(&d), fmt, ap)) >= 0) {
+  s = sink_dynstr(&d);
+  n = byte_vsinkprintf(s, fmt, ap);
+  xfree(s);
+  if(n >= 0) {
     dynstr_terminate(&d);
     *ptrp = d.vec;
   }