diff options
43 files changed, 212 insertions, 130 deletions
@@ -29,9 +29,9 @@ typedef struct Affinity_ { }*/ Affinity* Affinity_new(ProcessList* pl) { - Affinity* this = calloc(1, sizeof(Affinity)); + Affinity* this = xCalloc(1, sizeof(Affinity)); this->size = 8; - this->cpus = calloc(this->size, sizeof(int)); + this->cpus = xCalloc(this->size, sizeof(int)); this->pl = pl; return this; } @@ -44,7 +44,7 @@ void Affinity_delete(Affinity* this) { void Affinity_add(Affinity* this, int id) { if (this->used == this->size) { this->size *= 2; - this->cpus = realloc(this->cpus, sizeof(int) * this->size); + this->cpus = xRealloc(this->cpus, sizeof(int) * this->size); } this->cpus[this->used] = id; this->used++; diff --git a/AffinityPanel.c b/AffinityPanel.c index 41f520b5..03bfa753 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -60,7 +60,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) { } else { mode = false; } - Panel_add(this, (Object*) CheckItem_newByVal(strdup(number), mode)); + Panel_add(this, (Object*) CheckItem_newByVal(xStrdup(number), mode)); } return this; } @@ -140,7 +140,7 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { static void AllCPUsMeter_init(Meter* this) { int cpus = this->pl->cpuCount; if (!this->drawData) - this->drawData = calloc(cpus, sizeof(Meter*)); + this->drawData = xCalloc(cpus, sizeof(Meter*)); Meter** meters = (Meter**) this->drawData; int start, count; AllCPUsMeter_getRange(this, &start, &count); diff --git a/ColorsPanel.c b/ColorsPanel.c index 6072aedc..96199c1b 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -106,7 +106,7 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) { Panel_setHeader(super, "Colors"); for (int i = 0; ColorSchemeNames[i] != NULL; i++) { - Panel_add(super, (Object*) CheckItem_newByVal(strdup(ColorSchemeNames[i]), false)); + Panel_add(super, (Object*) CheckItem_newByVal(xStrdup(ColorSchemeNames[i]), false)); } CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true); return this; diff --git a/ColumnsPanel.c b/ColumnsPanel.c index e6fd7601..3ec9ee80 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -155,7 +155,7 @@ void ColumnsPanel_update(Panel* super) { ColumnsPanel* this = (ColumnsPanel*) super; int size = Panel_size(super); this->settings->changed = true; - this->settings->fields = realloc(this->settings->fields, sizeof(ProcessField) * (size+1)); + this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1)); this->settings->flags = 0; for (int i = 0; i < size; i++) { int key = ((ListItem*) Panel_get(super, i))->key; diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 2b826e09..fbf30795 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -83,19 +83,19 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* this->scr = scr; Panel_setHeader(super, "Display options"); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Tree view"), &(settings->treeView))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Shadow other users' processes"), &(settings->shadowOtherUsers))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Hide kernel threads"), &(settings->hideKernelThreads))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Hide userland threads"), &(settings->hideUserlandThreads))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Display threads in a different color"), &(settings->highlightThreads))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Show custom thread names"), &(settings->showThreadNames))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Show program path"), &(settings->showProgramPath))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Highlight program \"basename\""), &(settings->highlightBaseName))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Leave a margin around header"), &(settings->headerMargin))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Update process names on every refresh"), &(settings->updateProcessNames))); - Panel_add(super, (Object*) CheckItem_newByRef(strdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Tree view"), &(settings->treeView))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Shadow other users' processes"), &(settings->shadowOtherUsers))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide kernel threads"), &(settings->hideKernelThreads))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide userland threads"), &(settings->hideUserlandThreads))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Display threads in a different color"), &(settings->highlightThreads))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show custom thread names"), &(settings->showThreadNames))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show program path"), &(settings->showProgramPath))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight program \"basename\""), &(settings->highlightBaseName))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Leave a margin around header"), &(settings->headerMargin))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames))); + Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter))); return this; } diff --git a/EnvScreen.c b/EnvScreen.c index f8645ed5..4414c390 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -29,7 +29,7 @@ InfoScreenClass EnvScreen_class = { }; EnvScreen* EnvScreen_new(Process* process) { - EnvScreen* this = malloc(sizeof(EnvScreen)); + EnvScreen* this = xMalloc(sizeof(EnvScreen)); Object_setClass(this, Class(EnvScreen)); return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " "); } diff --git a/FunctionBar.c b/FunctionBar.c index ab44839a..659f4108 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -8,6 +8,7 @@ in the source distribution for its full text. #include "FunctionBar.h" #include "CRT.h" #include "RichString.h" +#include "XAlloc.h" #include <assert.h> #include <string.h> @@ -42,21 +43,21 @@ FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) { } FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* events) { - FunctionBar* this = calloc(1, sizeof(FunctionBar)); - this->functions = calloc(16, sizeof(char*)); + FunctionBar* this = xCalloc(1, sizeof(FunctionBar)); + this->functions = xCalloc(16, sizeof(char*)); if (!functions) { functions = FunctionBar_FLabels; } for (int i = 0; i < 15 && functions[i]; i++) { - this->functions[i] = strdup(functions[i]); + this->functions[i] = xStrdup(functions[i]); } if (keys && events) { this->staticData = false; - this->keys = calloc(15, sizeof(char*)); - this->events = calloc(15, sizeof(int)); + this->keys = xCalloc(15, sizeof(char*)); + this->events = xCalloc(15, sizeof(int)); int i = 0; while (i < 15 && functions[i]) { - this->keys[i] = strdup(keys[i]); + this->keys[i] = xStrdup(keys[i]); this->events[i] = events[i]; i++; } @@ -89,7 +90,7 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) { for (int i = 0; i < this->size; i++) { if (this->events[i] == event) { free(this->functions[i]); - this->functions[i] = strdup(text); + this->functions[i] = xStrdup(text); break; } } diff --git a/Hashtable.c b/Hashtable.c index 9cb2f932..b3eac8da 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "Hashtable.h" +#include "XAlloc.h" #include <stdlib.h> #include <assert.h> @@ -63,7 +64,7 @@ int Hashtable_count(Hashtable* this) { static HashtableItem* HashtableItem_new(unsigned int key, void* value) { HashtableItem* this; - this = malloc(sizeof(HashtableItem)); + this = xMalloc(sizeof(HashtableItem)); this->key = key; this->value = value; this->next = NULL; @@ -73,10 +74,10 @@ static HashtableItem* HashtableItem_new(unsigned int key, void* value) { Hashtable* Hashtable_new(int size, bool owner) { Hashtable* this; - this = malloc(sizeof(Hashtable)); + this = xMalloc(sizeof(Hashtable)); this->items = 0; this->size = size; - this->buckets = (HashtableItem**) calloc(size, sizeof(HashtableItem*)); + this->buckets = (HashtableItem**) xCalloc(size, sizeof(HashtableItem*)); this->owner = owner; assert(Hashtable_isConsistent(this)); return this; @@ -41,8 +41,8 @@ typedef struct Header_ { #endif Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) { - Header* this = calloc(1, sizeof(Header)); - this->columns = calloc(nrColumns, sizeof(Vector*)); + Header* this = xCalloc(1, sizeof(Header)); + this->columns = xCalloc(nrColumns, sizeof(Vector*)); this->settings = settings; this->pl = pl; this->nrColumns = nrColumns; @@ -83,13 +83,13 @@ void Header_writeBackToSettings(const Header* this) { Vector* vec = this->columns[col]; int len = Vector_size(vec); - colSettings->names = calloc(len+1, sizeof(char*)); - colSettings->modes = calloc(len, sizeof(int)); + colSettings->names = xCalloc(len+1, sizeof(char*)); + colSettings->modes = xCalloc(len, sizeof(int)); colSettings->len = len; for (int i = 0; i < len; i++) { Meter* meter = (Meter*) Vector_get(vec, i); - char* name = calloc(64, sizeof(char)); + char* name = xCalloc(64, sizeof(char)); if (meter->param) { snprintf(name, 63, "%s(%d)", As_Meter(meter)->name, meter->param); } else { @@ -151,7 +151,7 @@ char* Header_readMeterName(Header* this, int i, int column) { int nameLen = strlen(Meter_name(meter)); int len = nameLen + 100; - char* name = malloc(len); + char* name = xMalloc(len); strncpy(name, Meter_name(meter), nameLen); name[nameLen] = '\0'; if (meter->param) @@ -76,7 +76,7 @@ static inline void IncMode_done(IncMode* mode) { } IncSet* IncSet_new(FunctionBar* bar) { - IncSet* this = calloc(1, sizeof(IncSet)); + IncSet* this = xCalloc(1, sizeof(IncSet)); IncMode_initSearch(&(this->modes[INC_SEARCH])); IncMode_initFilter(&(this->modes[INC_FILTER])); this->active = NULL; @@ -61,7 +61,7 @@ ObjectClass ListItem_class = { ListItem* ListItem_new(const char* value, int key) { ListItem* this = AllocThis(ListItem); - this->value = strdup(value); + this->value = xStrdup(value); this->key = key; this->moving = false; return this; @@ -71,7 +71,7 @@ void ListItem_append(ListItem* this, const char* text) { int oldLen = strlen(this->value); int textLen = strlen(text); int newLen = strlen(this->value) + textLen; - this->value = realloc(this->value, newLen + 1); + this->value = xRealloc(this->value, newLen + 1); memcpy(this->value + oldLen, text, textLen); this->value[newLen] = '\0'; } diff --git a/MainPanel.c b/MainPanel.c index 336cfa46..f9b45d64 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -190,7 +190,7 @@ PanelClass MainPanel_class = { MainPanel* MainPanel_new() { MainPanel* this = AllocThis(MainPanel); Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, FunctionBar_new(MainFunctions, NULL, NULL)); - this->keys = calloc(KEY_MAX, sizeof(Htop_Action)); + this->keys = xCalloc(KEY_MAX, sizeof(Htop_Action)); this->inc = IncSet_new(MainPanel_getFunctionBar(this)); Action_setBindings(this->keys); diff --git a/Makefile.am b/Makefile.am index df122595..8b316270 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,7 +24,7 @@ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ SignalsPanel.c StringUtils.c SwapMeter.c TasksMeter.c UptimeMeter.c \ TraceScreen.c UsersTable.c Vector.c AvailableColumnsPanel.c AffinityPanel.c \ HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c EnvScreen.c \ -InfoScreen.c +InfoScreen.c XAlloc.c myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ @@ -34,7 +34,7 @@ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h ScreenManager.h Settings.h SignalsPanel.h StringUtils.h SwapMeter.h \ TasksMeter.h UptimeMeter.h TraceScreen.h UsersTable.h Vector.h Process.h \ AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \ -EnvScreen.h InfoScreen.h +EnvScreen.h InfoScreen.h XAlloc.h if HTOP_LINUX htop_CFLAGS += -rdynamic @@ -127,7 +127,7 @@ MeterClass Meter_class = { }; Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) { - Meter* this = calloc(1, sizeof(Meter)); + Meter* this = xCalloc(1, sizeof(Meter)); Object_setClass(this, type); this->h = 1; this->param = param; @@ -137,9 +137,9 @@ Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) { maxItems = 1; } type->curItems = maxItems; - this->values = calloc(maxItems, sizeof(double)); + this->values = xCalloc(maxItems, sizeof(double)); this->total = type->total; - this->caption = strdup(type->caption); + this->caption = xStrdup(type->caption); if (Meter_initFn(this)) Meter_init(this); Meter_setMode(this, type->defaultMode); @@ -193,7 +193,7 @@ void Meter_delete(Object* cast) { void Meter_setCaption(Meter* this, const char* caption) { free(this->caption); - this->caption = strdup(caption); + this->caption = xStrdup(caption); } static inline void Meter_displayBuffer(Meter* this, char* buffer, RichString* out) { @@ -366,7 +366,7 @@ static int GraphMeterMode_pixPerRow; static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { - if (!this->drawData) this->drawData = calloc(1, sizeof(GraphData)); + if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData)); GraphData* data = (GraphData*) this->drawData; const int nValues = METER_BUFFER_LEN; @@ -9,6 +9,7 @@ in the source distribution for its full text. /*{ #include "RichString.h" +#include "XAlloc.h" typedef struct Object_ Object; @@ -26,7 +27,7 @@ typedef void(*Object_Delete)(Object*); #define Class(class_) ((ObjectClass*)(&(class_ ## _class))) -#define AllocThis(class_) (class_*) malloc(sizeof(class_)); Object_setClass(this, Class(class_)); +#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); typedef struct ObjectClass_ { const void* extends; @@ -10,6 +10,7 @@ in the source distribution for its full text. */ #include "RichString.h" +#include "XAlloc.h" typedef struct Object_ Object; @@ -27,7 +28,7 @@ typedef void(*Object_Delete)(Object*); #define Class(class_) ((ObjectClass*)(&(class_ ## _class))) -#define AllocThis(class_) (class_*) malloc(sizeof(class_)); Object_setClass(this, Class(class_)); +#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); typedef struct ObjectClass_ { const void* extends; diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 096ed939..1eda3731 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -58,7 +58,7 @@ InfoScreenClass OpenFilesScreen_class = { }; OpenFilesScreen* OpenFilesScreen_new(Process* process) { - OpenFilesScreen* this = malloc(sizeof(OpenFilesScreen)); + OpenFilesScreen* this = xMalloc(sizeof(OpenFilesScreen)); Object_setClass(this, Class(OpenFilesScreen)); if (Process_isThread(process)) this->pid = process->tgid; @@ -79,7 +79,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { char command[1025]; snprintf(command, 1024, "lsof -P -p %d -F 2> /dev/null", pid); FILE* fd = popen(command, "r"); - OpenFiles_ProcessData* pdata = calloc(1, sizeof(OpenFiles_ProcessData)); + OpenFiles_ProcessData* pdata = xCalloc(1, sizeof(OpenFiles_ProcessData)); OpenFiles_FileData* fdata = NULL; OpenFiles_Data* item = &(pdata->data); if (!fd) { @@ -90,7 +90,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { int cmd = fgetc(fd); if (cmd == EOF) break; - char* entry = malloc(1024); + char* entry = xMalloc(1024); if (!fgets(entry, 1024, fd)) { free(entry); break; @@ -98,7 +98,7 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { char* newline = strrchr(entry, '\n'); *newline = '\0'; if (cmd == 'f') { - OpenFiles_FileData* nextFile = calloc(1, sizeof(OpenFiles_FileData)); + OpenFiles_FileData* nextFile = xCalloc(1, sizeof(OpenFiles_FileData)); if (fdata == NULL) { pdata->files = nextFile; } else { @@ -97,7 +97,7 @@ PanelClass Panel_class = { Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar) { Panel* this; - this = malloc(sizeof(Panel)); + this = xMalloc(sizeof(Panel)); Object_setClass(this, Class(Panel)); Panel_init(this, x, y, w, h, type, owner, fuBar); return this; @@ -455,7 +455,7 @@ bool Panel_onKey(Panel* this, int key) { HandlerResult Panel_selectByTyping(Panel* this, int ch) { int size = Panel_size(this); if (!this->eventHandlerState) - this->eventHandlerState = calloc(100, sizeof(char)); + this->eventHandlerState = xCalloc(100, sizeof(char)); char* buffer = this->eventHandlerState; if (ch < 255 && isalnum(ch)) { diff --git a/RichString.c b/RichString.c index 75198330..e7dd4e83 100644 --- a/RichString.c +++ b/RichString.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "RichString.h" +#include "XAlloc.h" #include <stdlib.h> #include <string.h> @@ -67,7 +68,7 @@ typedef struct RichString_ { static void RichString_extendLen(RichString* this, int len) { if (this->chlen <= RICHSTRING_MAXLEN) { if (len > RICHSTRING_MAXLEN) { - this->chptr = malloc(charBytes(len + 1)); + this->chptr = xMalloc(charBytes(len + 1)); memcpy(this->chptr, this->chstr, charBytes(this->chlen)); } } else { @@ -76,7 +77,7 @@ static void RichString_extendLen(RichString* this, int len) { free(this->chptr); this->chptr = this->chstr; } else { - this->chptr = realloc(this->chptr, charBytes(len + 1)); + this->chptr = xRealloc(this->chptr, charBytes(len + 1)); } } diff --git a/ScreenManager.c b/ScreenManager.c index 1a9d9f03..a33d3420 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -46,7 +46,7 @@ typedef struct ScreenManager_ { ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner) { ScreenManager* this; - this = malloc(sizeof(ScreenManager)); + this = xMalloc(sizeof(ScreenManager)); this->x1 = x1; this->y1 = y1; this->x2 = x2; @@ -96,7 +96,7 @@ static void Settings_readMeterModes(Settings* this, char* line, int column) { len++; } this->columns[column].len = len; - int* modes = calloc(len, sizeof(int)); + int* modes = xCalloc(len, sizeof(int)); for (int i = 0; i < len; i++) { modes[i] = atoi(ids[i]); } @@ -110,27 +110,27 @@ static void Settings_defaultMeters(Settings* this) { sizes[1]++; } for (int i = 0; i < 2; i++) { - this->columns[i].names = calloc(sizes[i] + 1, sizeof(char*)); - this->columns[i].modes = calloc(sizes[i], sizeof(int)); + this->columns[i].names = xCalloc(sizes[i] + 1, sizeof(char*)); + this->columns[i].modes = xCalloc(sizes[i], sizeof(int)); this->columns[i].len = sizes[i]; } int r = 0; if (this->cpuCount > 8) { - this->columns[0].names[0] = strdup("LeftCPUs2"); - this->columns[1].names[r++] = strdup("RightCPUs2"); + this->columns[0].names[0] = xStrdup("LeftCPUs2"); + this->columns[1].names[r++] = xStrdup("RightCPUs2"); } else if (this->cpuCount > 4) { - this->columns[0].names[0] = strdup("LeftCPUs"); - this->columns[1].names[r++] = strdup("RightCPUs"); + this->columns[0].names[0] = xStrdup("LeftCPUs"); + this->columns[1].names[r++] = xStrdup("RightCPUs"); } else { - this->columns[0].names[0] = strdup("AllCPUs"); + this->columns[0].names[0] = xStrdup("AllCPUs"); } - this->columns[0].names[1] = strdup("Memory"); - this->columns[0].names[2] = strdup("Swap"); + this->columns[0].names[1] = xStrdup("Memory"); + this->columns[0].names[2] = xStrdup("Swap"); - this->columns[1].names[r++] = strdup("Tasks"); - this->columns[1].names[r++] = strdup("LoadAverage"); - this->columns[1].names[r++] = strdup("Uptime"); + this->columns[1].names[r++] = xStrdup("Tasks"); + this->columns[1].names[r++] = xStrdup("LoadAverage"); + this->columns[1].names[r++] = xStrdup("Uptime"); } static void readFields(ProcessField* fields, int* flags, const char* line) { @@ -306,7 +306,7 @@ bool Settings_write(Settings* this) { Settings* Settings_new(int cpuCount) { - Settings* this = calloc(1, sizeof(Settings)); + Settings* this = xCalloc(1, sizeof(Settings)); this->sortKey = PERCENT_CPU; this->direction = 1; @@ -325,7 +325,7 @@ Settings* Settings_new(int cpuCount) { this->showProgramPath = true; this->highlightThreads = true; - this->fields = calloc(Platform_numberOfFields+1, sizeof(ProcessField)); + this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). this->flags = 0; @@ -338,7 +338,7 @@ Settings* Settings_new(int cpuCount) { char* legacyDotfile = NULL; char* rcfile = getenv("HTOPRC"); if (rcfile) { - this->filename = strdup(rcfile); + this->filename = xStrdup(rcfile); } else { const char* home = getenv("HOME"); if (!home) home = ""; @@ -347,7 +347,7 @@ Settings* Settings_new(int cpuCount) { char* htopDir = NULL; if (xdgConfigHome) { this->filename = String_cat(xdgConfigHome, "/htop/htoprc"); - configDir = strdup(xdgConfigHome); + configDir = xStrdup(xdgConfigHome); htopDir = String_cat(xdgConfigHome, "/htop"); } else { this->filename = String_cat(home, "/.config/htop/htoprc"); diff --git a/StringUtils.c b/StringUtils.c index ec123e9f..173caba5 100644 --- a/StringUtils.c +++ b/StringUtils.c @@ -6,6 +6,7 @@ in the source distribution for its full text. */ #include "StringUtils.h" +#include "XAlloc.h" #include "config.h" @@ -22,7 +23,7 @@ in the source distribution for its full text. char* String_cat(const char* s1, const char* s2) { int l1 = strlen(s1); int l2 = strlen(s2); - char* out = malloc(l1 + l2 + 1); + char* out = xMalloc(l1 + l2 + 1); strncpy(out, s1, l1); strncpy(out+l1, s2, l2+1); return out; @@ -36,7 +37,7 @@ char* String_trim(const char* in) { while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { len--; } - char* out = malloc(len+1); + char* out = xMalloc(len+1); strncpy(out, in, len); out[len] = '\0'; |