mirror of https://github.com/xzeldon/htop.git
Use strdup explicitly
This commit is contained in:
parent
93233a67ea
commit
81e44312b4
|
@ -38,7 +38,7 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity) {
|
||||||
} else {
|
} else {
|
||||||
mode = false;
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
|
||||||
What's new in version 1.0.1
|
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.
|
* 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,
|
* BUGFIX: keep main panel up-to-date when running the screen manager,
|
||||||
to fix crash when processes die while on the F9/Kill screen.
|
to fix crash when processes die while on the F9/Kill screen.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
#include "ColorsPanel.h"
|
#include "ColorsPanel.h"
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ ColorsPanel* ColorsPanel_new(Settings* settings, ScreenManager* scr) {
|
||||||
|
|
||||||
Panel_setHeader(super, "Colors");
|
Panel_setHeader(super, "Colors");
|
||||||
for (int i = 0; ColorSchemes[i] != NULL; i++) {
|
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);
|
CheckItem_set((CheckItem*)Panel_get(super, settings->colorScheme), true);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#ifndef HEADER_ColorsPanel
|
#ifndef HEADER_ColorsPanel
|
||||||
#define HEADER_ColorsPanel
|
#define HEADER_ColorsPanel
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "CRT.h"
|
#include "CRT.h"
|
||||||
|
|
||||||
#include "Panel.h"
|
#include "Panel.h"
|
||||||
|
|
|
@ -65,16 +65,16 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
|
||||||
super->eventHandler = DisplayOptionsPanel_eventHandler;
|
super->eventHandler = DisplayOptionsPanel_eventHandler;
|
||||||
|
|
||||||
Panel_setHeader(super, "Display options");
|
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(strdup("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(strdup("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(strdup("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(strdup("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(strdup("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(strdup("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(strdup("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(strdup("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(strdup("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(strdup("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("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,8 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve
|
||||||
this->events = malloc(sizeof(int) * 15);
|
this->events = malloc(sizeof(int) * 15);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < 15 && functions[i]) {
|
while (i < 15 && functions[i]) {
|
||||||
this->functions[i] = String_copy(functions[i]);
|
this->functions[i] = strdup(functions[i]);
|
||||||
this->keys[i] = String_copy(keys[i]);
|
this->keys[i] = strdup(keys[i]);
|
||||||
this->events[i] = events[i];
|
this->events[i] = events[i];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
|
||||||
for (int i = 0; i < this->size; i++) {
|
for (int i = 0; i < this->size; i++) {
|
||||||
if (this->events[i] == event) {
|
if (this->events[i] == event) {
|
||||||
free(this->functions[i]);
|
free(this->functions[i]);
|
||||||
this->functions[i] = String_copy(text);
|
this->functions[i] = strdup(text);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ ListItem* ListItem_new(const char* value, int key) {
|
||||||
Object_setClass(this, LISTITEM_CLASS);
|
Object_setClass(this, LISTITEM_CLASS);
|
||||||
((Object*)this)->display = ListItem_display;
|
((Object*)this)->display = ListItem_display;
|
||||||
((Object*)this)->delete = ListItem_delete;
|
((Object*)this)->delete = ListItem_delete;
|
||||||
this->value = String_copy(value);
|
this->value = strdup(value);
|
||||||
this->key = key;
|
this->key = key;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdbool.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.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#include "config.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
|
@ -617,7 +617,7 @@ static bool ProcessList_readCmdlineFile(Process* process, const char* dirname, c
|
||||||
command[amtRead] = '\0';
|
command[amtRead] = '\0';
|
||||||
fclose(file);
|
fclose(file);
|
||||||
free(process->comm);
|
free(process->comm);
|
||||||
process->comm = String_copy(command);
|
process->comm = strdup(command);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,11 +710,11 @@ static bool ProcessList_processEntries(ProcessList* this, const char* dirname, P
|
||||||
|
|
||||||
if (process->state == 'Z') {
|
if (process->state == 'Z') {
|
||||||
free(process->comm);
|
free(process->comm);
|
||||||
process->comm = String_copy(command);
|
process->comm = strdup(command);
|
||||||
} else if (Process_isThread(process)) {
|
} else if (Process_isThread(process)) {
|
||||||
if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') {
|
if (this->showThreadNames || Process_isKernelThread(process) || process->state == 'Z') {
|
||||||
free(process->comm);
|
free(process->comm);
|
||||||
process->comm = String_copy(command);
|
process->comm = strdup(command);
|
||||||
} else if (this->showingThreadNames) {
|
} else if (this->showingThreadNames) {
|
||||||
if (! ProcessList_readCmdlineFile(process, dirname, name))
|
if (! ProcessList_readCmdlineFile(process, dirname, name))
|
||||||
goto errorReadingProcess;
|
goto errorReadingProcess;
|
||||||
|
|
|
@ -9,6 +9,7 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
#include "Header.h"
|
#include "Header.h"
|
||||||
|
|
6
String.c
6
String.c
|
@ -5,7 +5,7 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#include "config.h"
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.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))
|
#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) {
|
char* String_cat(const char* s1, const char* s2) {
|
||||||
int l1 = strlen(s1);
|
int l1 = strlen(s1);
|
||||||
int l2 = strlen(s2);
|
int l2 = strlen(s2);
|
||||||
|
|
3
String.h
3
String.h
|
@ -9,6 +9,7 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <stdlib.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))
|
#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_cat(const char* s1, const char* s2);
|
||||||
|
|
||||||
char* String_trim(const char* in);
|
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.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "UsersTable.h"
|
#include "UsersTable.h"
|
||||||
#include "Hashtable.h"
|
#include "Hashtable.h"
|
||||||
#include "String.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -40,7 +41,7 @@ char* UsersTable_getRef(UsersTable* this, unsigned int uid) {
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
struct passwd* userData = getpwuid(uid);
|
struct passwd* userData = getpwuid(uid);
|
||||||
if (userData != NULL) {
|
if (userData != NULL) {
|
||||||
name = String_copy(userData->pw_name);
|
name = strdup(userData->pw_name);
|
||||||
Hashtable_put(this->users, uid, 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.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "Hashtable.h"
|
#include "Hashtable.h"
|
||||||
#include "String.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
4
htop.c
4
htop.c
|
@ -5,7 +5,8 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#include "config.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -29,7 +30,6 @@ in the source distribution for its full text.
|
||||||
#include "OpenFilesScreen.h"
|
#include "OpenFilesScreen.h"
|
||||||
#include "AffinityPanel.h"
|
#include "AffinityPanel.h"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
//#link m
|
//#link m
|
||||||
|
|
4
htop.h
4
htop.h
|
@ -9,7 +9,8 @@ Released under the GNU GPL, see the COPYING file
|
||||||
in the source distribution for its full text.
|
in the source distribution for its full text.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _GNU_SOURCE
|
#include "config.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
@ -33,7 +34,6 @@ in the source distribution for its full text.
|
||||||
#include "OpenFilesScreen.h"
|
#include "OpenFilesScreen.h"
|
||||||
#include "AffinityPanel.h"
|
#include "AffinityPanel.h"
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
//#link m
|
//#link m
|
||||||
|
|
Loading…
Reference in New Issue