From a0316f63985074956d217f78f9bca26543473867 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Sun, 24 Aug 2025 22:45:47 +0200 Subject: Object::toString() free responsibility to caller It already was the caller responsibility, but it was documented as not being so, with a todo comment. Until other implementation is provided, this was leaking memory. No need to keep the const. --- lout/object.cc | 6 +++--- lout/object.hh | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'lout') diff --git a/lout/object.cc b/lout/object.cc index 5c2ee433..5745e03d 100644 --- a/lout/object.cc +++ b/lout/object.cc @@ -2,6 +2,7 @@ * Dillo Widget * * Copyright 2005-2007 Sebastian Geerken + * Copyright 2025 Rodrigo Arias Mallo * * 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 @@ -76,12 +77,11 @@ Object *Object::clone() * \brief Use object::Object::intoStringBuffer to return a textual * representation of the object. * - * The caller does not have to free the memory, object::Object is responsible + * The caller must free the memory, object::Object is not responsible * for this. */ -const char *Object::toString() +char *Object::toString() { - /** \todo garbage! */ misc::StringBuffer sb; intoStringBuffer(&sb); char *s = dStrdup(sb.getChars()); diff --git a/lout/object.hh b/lout/object.hh index 9cacff77..c9fa0458 100644 --- a/lout/object.hh +++ b/lout/object.hh @@ -1,3 +1,23 @@ +/* + * Dillo Widget + * + * Copyright 2005-2007 Sebastian Geerken + * Copyright 2025 Rodrigo Arias Mallo + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef __LOUT_OBJECT_HH__ #define __LOUT_OBJECT_HH__ @@ -29,7 +49,7 @@ public: virtual int hashValue(); virtual Object *clone(); virtual void intoStringBuffer(misc::StringBuffer *sb); - const char *toString(); + char *toString(); virtual size_t sizeOf(); }; -- cgit v1.2.3