[Kst] kdeextragear-2/kst/kst [POSSIBLY UNSAFE]
George Staikos
staikos at kde.org
Tue Jul 13 21:48:35 CEST 2004
CVS commit by staikos:
integrate memory checker to circumvent overcommit on Linux
M +35 -0 kstdatacollection.cpp 1.9 [POSSIBLY UNSAFE: qDebug]
M +6 -0 kstdatacollection.h 1.15
M +3 -2 kstdatasource.cpp 1.21
M +4 -7 ksthistogram.cpp 1.23
M +2 -2 kstvector.cpp 1.73
M +5 -1 procps.h 1.2
--- kdeextragear-2/kst/kst/kstdatacollection.cpp #1.8:1.9
@@ -16,7 +16,17 @@
***************************************************************************/
+#include <config.h>
+
+#include <stdlib.h>
+
#include "kstdatacollection.h"
#include "kstrvector.h"
+#ifdef HAVE_LINUX
+#include "sysinfo.h"
+#include "psversion.h"
+#define S(X) ((unsigned long long)(X) << 10)
+#endif
+
/** The list of data sources (files) */
KstDataSourceList KST::dataSourceList;
@@ -50,2 +60,27 @@ void KST::addVectorToList(KstVectorPtr v
}
+void *KST::realloc(void *ptr, size_t size) {
+#ifdef HAVE_LINUX
+ meminfo();
+ unsigned long bFree = S(kb_main_free + kb_main_buffers + kb_main_cached);
+ if (size > bFree) {
+ qDebug("Tried to allocate too much memory! (Wanted %u, had %lu)", size, bFree);
+ return 0L;
+ }
+#endif
+ return ::realloc(ptr, size);
+}
+
+void *KST::malloc(size_t size) {
+#ifdef HAVE_LINUX
+ meminfo();
+ unsigned long bFree = S(kb_main_free + kb_main_buffers + kb_main_cached);
+ if (size > bFree) {
+ qDebug("Tried to allocate too much memory! (Wanted %u, had %lu)", size, bFree);
+ return 0L;
+ }
+#endif
+ return ::malloc(size);
+}
+
+// vim: ts=2 sw=2 et
--- kdeextragear-2/kst/kst/kstdatacollection.h #1.14:1.15
@@ -56,5 +56,11 @@ namespace KST {
extern void addVectorToList(KstVectorPtr v);
+
+ /** Bad choice for location - maybe move it later */
+ void *malloc(size_t size);
+ void *realloc(void *ptr, size_t size);
+
}
#endif
+// vim: ts=2 sw=2 et
--- kdeextragear-2/kst/kst/kstdatasource.cpp #1.20:1.21
@@ -29,4 +29,5 @@
#include <qstylesheet.h>
+#include "kstdatacollection.h"
#include "kstdebug.h"
#include "stdinsource.h"
@@ -309,5 +310,5 @@ void KstDataSource::virtual_hook(int id,
void *KstDataSource::bufferMalloc(size_t size) {
- return ::malloc(size);
+ return KST::malloc(size);
}
@@ -319,5 +320,5 @@ void KstDataSource::bufferFree(void *ptr
void *KstDataSource::bufferRealloc(void *ptr, size_t size) {
- return ::realloc(ptr, size);
+ return KST::realloc(ptr, size);
}
--- kdeextragear-2/kst/kst/ksthistogram.cpp #1.22:1.23
@@ -133,5 +133,5 @@ void KstHistogram::commonConstructor(con
NBins = 2;
}
- Bins = (unsigned long *)malloc(in_n_bins*sizeof(unsigned long *));
+ Bins = new unsigned long[in_n_bins];
Color = in_color;
@@ -141,8 +141,5 @@ void KstHistogram::commonConstructor(con
KstHistogram::~KstHistogram() {
- if (Bins != NULL) {
- free(Bins);
- Bins = NULL;
- }
+ delete[] Bins;
}
@@ -250,10 +247,10 @@ void KstHistogram::setXRange(double xmin
void KstHistogram::setNBins(int in_n_bins) {
- if (Bins!=NULL) free(Bins);
+ delete[] Bins;
NBins = in_n_bins;
if (NBins<2) NBins = 2;
- Bins = (unsigned long *)malloc(in_n_bins*sizeof(unsigned long *));
+ Bins = new unsigned long[in_n_bins];
W = (MaxX - MinX)/(double)NBins;
}
--- kdeextragear-2/kst/kst/kstvector.cpp #1.72:1.73
@@ -107,5 +107,5 @@ KstVector::KstVector(const QString& name
}
- _v = static_cast<double*>(malloc(size*sizeof(double)));
+ _v = static_cast<double*>(KST::malloc(size*sizeof(double)));
_size = size;
_is_rising = false;
@@ -258,5 +258,5 @@ bool KstVector::resize(int sz, bool rein
//kdDebug() << "resizing to: " << sz << endl;
if (sz > 1) {
- _v = static_cast<double*>(realloc(_v, sz*sizeof(double)));
+ _v = static_cast<double*>(KST::realloc(_v, sz*sizeof(double)));
if (!_v) {
return false;
--- kdeextragear-2/kst/kst/procps.h #1.1:1.2
@@ -39,4 +39,8 @@
#define FUNCTION __attribute__((__const__)) /* no access to global mem, even via ptr, and no side effect */
+#ifndef __STDC_VERSION__
+#define __STDC_VERSION__ 0
+#endif
+
#if !defined(restrict) && __STDC_VERSION__ < 199901
#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
@@ -65,5 +69,5 @@
#endif
-#if SHARED==1 && (__GNUC__ > 2 || __GNUC_MINOR__ >= 96)
+#if defined(SHARED) && SHARED == 1 && (__GNUC__ > 2 || __GNUC_MINOR__ >= 96)
#define LABEL_OFFSET
#endif
More information about the Kst
mailing list