From 440ac41cf1dc09a4dde43790f9f9d5a83bfb4a45 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 9 Mar 2010 12:23:49 +0100 Subject: New memory allocators that exit on OOM and handle multiplication overflow Every place that does a regular malloc/calloc and aborts on failure should use spice_malloc/spice_mallo0 instead, which is leaner and cleaner. Allocations of dynamically sized arrays can use g_malloc_n or g_new etc which correctly handle multiplication overflow if some of the arguments are not trusted. --- client/mem.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 client/mem.cpp (limited to 'client/mem.cpp') diff --git a/client/mem.cpp b/client/mem.cpp new file mode 100644 index 00000000..b06bb3b6 --- /dev/null +++ b/client/mem.cpp @@ -0,0 +1,24 @@ +/* + Copyright (C) 2009 Red Hat, Inc. + + 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 2 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 . +*/ + +#include "common.h" +#include "utils.h" + +#define MALLOC_ERROR(format, ...) THROW(format, ## __VA_ARGS__) + +#include "../common/mem.c" + -- cgit