mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 12:14:36 +03:00
Add wrapper function for free and strdup
Reduces code in callers and helps avoiding memory leaks.
This commit is contained in:

committed by
BenBE

parent
958112c5a3
commit
70f48f1f44
8
XUtils.c
8
XUtils.c
@ -239,6 +239,14 @@ char* xStrdup(const char* str) {
|
||||
return data;
|
||||
}
|
||||
|
||||
void free_and_xStrdup(char** ptr, const char* str) {
|
||||
if (*ptr && String_eq(*ptr, str))
|
||||
return;
|
||||
|
||||
free(*ptr);
|
||||
*ptr = xStrdup(str);
|
||||
}
|
||||
|
||||
char* xStrndup(const char* str, size_t len) {
|
||||
char* data = strndup(str, len);
|
||||
if (!data) {
|
||||
|
Reference in New Issue
Block a user