Commit 81e44312 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Use strdup explicitly

parent 93233a67
......@@ -38,7 +38,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
} else {
mode = false;
}
Panel_add(this, (Object*) CheckItem_new(String_copy(number), NULL, mode));
Panel_add(this, (Object*) CheckItem_new(strdup(number), NULL, mode));
}
return this;
}
......
What's new in version 1.0.1
* Move .htoprc to XDG-compliant path ~/.config/htop/htoprc,
respecting $XDG_CONFIG_HOME
(thanks to Hadzhimurad Ustarkhan for the suggestion.)
* Safer behavior on the kill screen, to make it harder to kill the wrong process.
* BUGFIX: keep main panel up-to-date when running the screen manager,
to fix crash when processes die while on the F9/Kill screen.
......
#include "config.h"
#include "CRT.h"
#include "ColorsPanel.h"
......@@ -88,7 +89,7 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
Panel_setHeader(super, "Colors");
for (int i = 0; ColorSchemes[i] != NULL; i++) {
Panel_add(super, (Object*) CheckItem_new(String_copy(ColorSchemes[i]), NULL, false));
Panel_add(super, (Object*) CheckItem_new(strdup(ColorSchemes[i]), NULL, false));
}
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
return this;
......
......@@ -3,6 +3,7 @@
#ifndef HEADER_ColorsPanel
#define HEADER_ColorsPanel
#include "config.h"
#include "CRT.h"
#include "Panel.h"
......
......@@ -65,16 +65,16 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
super->eventHandler = DisplayOptionsPanel_eventHandler;
Panel_setHeader(super, "Display options");
Panel_add(super, (Object*) CheckItem_new(String_copy("Tree view"), &(settings->pl->treeView), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Display threads in a different color"), &(settings->pl->highlightThreads), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Show custom thread names"), &(settings->pl->showThreadNames), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Leave a margin around header"), &(settings->header->margin), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false));
Panel_add(super, (Object*) CheckItem_new(String_copy("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->pl->treeView), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->pl->hideKernelThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->pl->hideUserlandThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->pl->highlightThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->pl->showThreadNames), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->header->margin), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
return this;
}
......@@ -54,8 +54,8 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve
this->events = malloc(sizeof(int) * 15);
int i = 0;
while (i < 15 && functions[i]) {
this->functions[i] = String_copy(functions[i]);
this->keys[i] = String_copy(keys[i]);
this->functions[i] = strdup(functions[i]);
this->keys[i] = strdup(keys[i]);
this->events[i] = events[i];
i++;
}
......@@ -89,7 +89,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] = String_copy(text);
this->functions[i] = strdup(text);
break;
}
}
......
......@@ -49,7 +49,7 @@ ListItem* ListItem_new(const char* value, int key) {
Object_setClass(this, LISTITEM_CLASS);
((Object*)this)->display = ListItem_display;
((Object*)this)->delete = ListItem_delete;
this->value = String_copy(value);
this->value = strdup(value);
this->key = key;
return this;
}
......
......@@ -5,7 +5,6 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
......
......@@ -9,7 +9,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#define _GNU_SOURCE
#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>
......
......@@ -617,7 +617,7 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c
command[amtRead] = '\0';
fclose(file);
free(process->comm);
process->comm = String_copy(command);
process->comm = strdup(command);
return true;
}
......@@ -710,11 +710,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
if (process->state == 'Z') {
free(process->comm);
process->comm = String_copy(command);
process->comm = strdup(command);
} else if (Process_isThread(process)) {
if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') {
free(process->comm);
process->comm = String_copy(command);
process->comm = strdup(command);
} else if (this->showingThreadNames) {
if (! ProcessList_readCmdlineFile(process, dirname, name))
goto errorReadingProcess;
......
......@@ -9,6 +9,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "config.h"
#include "String.h"
#include "ProcessList.h"
#include "Header.h"
......
......@@ -5,7 +5,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#define _GNU_SOURCE
#include "config.h"
#include "String.h"
#include <string.h>
#include <strings.h>
......@@ -18,10 +18,6 @@ in the source distribution for its full text.
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
}*/
inline char* String_copy(const char* orig) {
return strdup(orig);
}
char* String_cat(const char* s1, const char* s2) {
int l1 = strlen(s1);
int l2 = strlen(s2);
......
......@@ -9,6 +9,7 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "config.h"
#include <string.h>
#include <strings.h>
#include <stdlib.h>
......@@ -18,8 +19,6 @@ in the source distribution for its full text.
#define String_startsWith(s, match) (strstr((s), (match)) == (s))
extern char* String_copy(const char* orig);
char* String_cat(const char* s1, const char* s2);
char* String_trim(const char* in);
......
......@@ -5,11 +5,12 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "config.h"
#include "UsersTable.h"
#include "Hashtable.h"
#include "String.h"
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <pwd.h>
#include <sys/types.h>
......@@ -40,7 +41,7 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
if (name == NULL) {
struct passwd* userData = getpwuid(uid);
if (userData != NULL) {
name = String_copy(userData->pw_name);
name = strdup(userData->pw_name);
Hashtable_put(this->users, uid, name);
}
}
......
......@@ -9,10 +9,11 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "config.h"
#include "Hashtable.h"
#include "String.h"
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <pwd.h>
#include <sys/types.h>
......
......@@ -5,7 +5,8 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#define _GNU_SOURCE
#include "config.h"
#include <unistd.h>
#include <math.h>
#include <sys/param.h>
......@@ -29,7 +30,6 @@ in the source distribution for its full text.
#include "OpenFilesScreen.h"
#include "AffinityPanel.h"
#include "config.h"
#include "debug.h"
//#link m
......
......@@ -9,7 +9,8 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#define _GNU_SOURCE
#include "config.h"
#include <unistd.h>
#include <math.h>
#include <sys/param.h>
......@@ -33,7 +34,6 @@ in the source distribution for its full text.
#include "OpenFilesScreen.h"
#include "AffinityPanel.h"
#include "config.h"
#include "debug.h"
//#link m
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment