From 3f855f07f5d2e9a08a586436719358c40a46f29d Mon Sep 17 00:00:00 2001 From: TingPing Date: Sun, 28 Dec 2014 06:08:20 -0500 Subject: Use glib for allocations in all plugins Continuation of 83032b1aa --- plugins/doat/Makefile.am | 4 +- plugins/doat/doat.c | 16 ++--- plugins/doat/doat.vcxproj | 8 ++- plugins/fishlim/Makefile.am | 2 +- plugins/fishlim/fish.c | 10 ++- plugins/fishlim/fish.h | 2 + plugins/fishlim/fishlim.vcxproj | 2 - plugins/fishlim/fishlim.vcxproj.filters | 6 -- plugins/fishlim/irc.h | 2 + plugins/fishlim/keystore.c | 13 +--- plugins/fishlim/keystore.h | 4 +- plugins/fishlim/misc.c | 54 --------------- plugins/fishlim/misc.h | 36 ---------- plugins/fishlim/plugin_hexchat.c | 8 +-- plugins/fishlim/test.c | 4 +- plugins/mpcinfo/functions.c | 6 +- plugins/mpcinfo/mpcInfo.c | 27 +++++--- plugins/mpcinfo/mpcinfo.vcxproj | 8 ++- plugins/perl/Makefile.am | 4 +- plugins/perl/perl.c | 113 ++++++++++---------------------- plugins/perl/perl.vcxproj | 14 ++-- plugins/python/python.c | 13 +--- plugins/sysinfo/match.c | 5 +- plugins/sysinfo/parse.c | 7 +- plugins/sysinfo/pci.c | 5 +- plugins/sysinfo/xsys.c | 2 +- 26 files changed, 118 insertions(+), 257 deletions(-) delete mode 100644 plugins/fishlim/misc.c delete mode 100644 plugins/fishlim/misc.h diff --git a/plugins/doat/Makefile.am b/plugins/doat/Makefile.am index 10b38cc6..a04d2863 100644 --- a/plugins/doat/Makefile.am +++ b/plugins/doat/Makefile.am @@ -3,6 +3,6 @@ libdir = $(hexchatlibdir) lib_LTLIBRARIES = doat.la doat_la_SOURCES = doat.c doat_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module -doat_la_LIBADD = -doat_la_CFLAGS = -I$(top_srcdir)/src/common +doat_la_LIBADD = $(GLIB_LIBS) +doat_la_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir)/src/common diff --git a/plugins/doat/doat.c b/plugins/doat/doat.c index 5e0aa4eb..1d1bfcdf 100644 --- a/plugins/doat/doat.c +++ b/plugins/doat/doat.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "hexchat-plugin.h" static hexchat_plugin *ph; @@ -33,7 +34,7 @@ parse_command( char *word[], char *word_eol[], void *userdata ) { break; } - channel = strdup( token ); + channel = g_strdup( token ); delimiter = strchr( channel, '/' ); @@ -42,13 +43,13 @@ parse_command( char *word[], char *word_eol[], void *userdata ) { *delimiter = '\0'; if( strlen( delimiter + 1 ) > 0 ) { - server = strdup( delimiter + 1 ); + server = g_strdup( delimiter + 1 ); } } /* /Network form */ if( strlen( channel ) == 0 ) { - free( channel ); + g_free( channel ); channel = NULL; } @@ -60,13 +61,8 @@ parse_command( char *word[], char *word_eol[], void *userdata ) { } } - if( channel != NULL ) { - free( channel ); - } - - if( server != NULL ) { - free( server ); - } + g_free( channel ); + g_free( server ); } } return HEXCHAT_EAT_HEXCHAT; diff --git a/plugins/doat/doat.vcxproj b/plugins/doat/doat.vcxproj index 171e2b0d..86c80f09 100644 --- a/plugins/doat/doat.vcxproj +++ b/plugins/doat/doat.vcxproj @@ -62,7 +62,7 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;DOAT_EXPORTS;%(PreprocessorDefinitions) - ..\..\src\common;%(AdditionalIncludeDirectories) + ..\..\src\common;$(Glib);%(AdditionalIncludeDirectories) true @@ -70,6 +70,8 @@ true true true + $(DepsRoot)\lib;%(AdditionalLibraryDirectories) + $(DepLibs);%(AdditionalDependencies) doat.def @@ -80,7 +82,7 @@ true true WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;DOAT_EXPORTS;%(PreprocessorDefinitions) - ..\..\src\common;%(AdditionalIncludeDirectories) + ..\..\src\common;$(Glib);%(AdditionalIncludeDirectories) true @@ -88,6 +90,8 @@ true true true + $(DepsRoot)\lib;%(AdditionalLibraryDirectories) + $(DepLibs);%(AdditionalDependencies) doat.def diff --git a/plugins/fishlim/Makefile.am b/plugins/fishlim/Makefile.am index c57a4de9..df541396 100644 --- a/plugins/fishlim/Makefile.am +++ b/plugins/fishlim/Makefile.am @@ -3,7 +3,7 @@ EXTRA_DIST = INSTALL LICENSE libdir = $(hexchatlibdir) lib_LTLIBRARIES = fishlim.la -fishlim_la_SOURCES = fish.c irc.c keystore.c misc.c plugin_hexchat.c +fishlim_la_SOURCES = fish.c irc.c keystore.c plugin_hexchat.c fishlim_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module fishlim_la_LIBADD = $(GLIB_LIBS) $(OPENSSL_LIBS) fishlim_la_CFLAGS = $(GLIB_CFLAGS) $(OPENSSL_CFLAGS) -I$(top_srcdir)/src/common diff --git a/plugins/fishlim/fish.c b/plugins/fishlim/fish.c index 93420f23..a230185d 100644 --- a/plugins/fishlim/fish.c +++ b/plugins/fishlim/fish.c @@ -75,9 +75,8 @@ char *fish_encrypt(const char *key, size_t keylen, const char *message) { messagelen = strlen(message); if (messagelen == 0) return NULL; - encrypted = malloc(((messagelen-1)/8)*12 + 12 + 1); // each 8-byte block becomes 12 bytes + encrypted = g_malloc(((messagelen - 1) / 8) * 12 + 12 + 1); // each 8-byte block becomes 12 bytes end = encrypted; - if (!encrypted) return NULL; while (*message) { // Read 8 bytes (a Blowfish block) @@ -124,9 +123,8 @@ char *fish_decrypt(const char *key, size_t keylen, const char *data) { unsigned char d; BF_set_key(&bfkey, keylen, (const unsigned char*)key); - decrypted = malloc(strlen(data)+1); + decrypted = g_malloc(strlen(data) + 1); end = decrypted; - if (!decrypted) return NULL; while (*data) { // Convert from FiSH-BASE64 @@ -172,7 +170,7 @@ char *fish_encrypt_for_nick(const char *nick, const char *data) { // Encrypt encrypted = fish_encrypt(key, strlen(key), data); - free(key); + g_free(key); return encrypted; } @@ -190,7 +188,7 @@ char *fish_decrypt_from_nick(const char *nick, const char *data) { // Decrypt decrypted = fish_decrypt(key, strlen(key), data); - free(key); + g_free(key); return decrypted; } diff --git a/plugins/fishlim/fish.h b/plugins/fishlim/fish.h index db471326..d7415a5a 100644 --- a/plugins/fishlim/fish.h +++ b/plugins/fishlim/fish.h @@ -28,6 +28,8 @@ #include #include +#include + char *fish_encrypt(const char *key, size_t keylen, const char *message); char *fish_decrypt(const char *key, size_t keylen, const char *data); char *fish_encrypt_for_nick(const char *nick, const char *data); diff --git a/plugins/fishlim/fishlim.vcxproj b/plugins/fishlim/fishlim.vcxproj index f1eb95ba..ca3de578 100644 --- a/plugins/fishlim/fishlim.vcxproj +++ b/plugins/fishlim/fishlim.vcxproj @@ -103,14 +103,12 @@ - - diff --git a/plugins/fishlim/fishlim.vcxproj.filters b/plugins/fishlim/fishlim.vcxproj.filters index 7c13733b..d8fbf454 100644 --- a/plugins/fishlim/fishlim.vcxproj.filters +++ b/plugins/fishlim/fishlim.vcxproj.filters @@ -32,9 +32,6 @@ Header Files - - Header Files - Header Files @@ -49,9 +46,6 @@ Source Files - - Source Files - Source Files diff --git a/plugins/fishlim/irc.h b/plugins/fishlim/irc.h index dc43185c..7ff72355 100644 --- a/plugins/fishlim/irc.h +++ b/plugins/fishlim/irc.h @@ -28,6 +28,8 @@ #include #include +#include + bool irc_parse_message(const char *words[], const char **prefix, const char **command, size_t *parameters_offset); diff --git a/plugins/fishlim/keystore.c b/plugins/fishlim/keystore.c index caad3628..964b4cb4 100644 --- a/plugins/fishlim/keystore.c +++ b/plugins/fishlim/keystore.c @@ -29,7 +29,6 @@ #include #include "irc.h" #include "fish.h" -#include "misc.h" #include "keystore.h" #include "plugin_hexchat.h" @@ -97,7 +96,7 @@ char *keystore_get_key(const char *nick) { if (strncmp(value, "+OK ", 4) != 0) { // Key is stored in plaintext - return import_glib_string(value); + return value; } else { // Key is encrypted const char *encrypted = value+4; @@ -191,7 +190,7 @@ bool keystore_store_key(const char *nick, const char *key) { // Store encrypted in file g_key_file_set_string(keyfile, nick, "key", wrapped); - free(wrapped); + g_free(wrapped); } else { // Store unencrypted in file g_key_file_set_string(keyfile, nick, "key", key); @@ -220,11 +219,3 @@ bool keystore_delete_nick(const char *nick) { g_key_file_free(keyfile); return ok; } - - -void keystore_secure_free(void *ptr, size_t size) { - secure_erase(ptr, size); - free(ptr); -} - - diff --git a/plugins/fishlim/keystore.h b/plugins/fishlim/keystore.h index a2c33f02..3c609867 100644 --- a/plugins/fishlim/keystore.h +++ b/plugins/fishlim/keystore.h @@ -28,11 +28,11 @@ #include #include +#include + char *keystore_get_key(const char *nick); bool keystore_store_key(const char *nick, const char *key); bool keystore_delete_nick(const char *nick); -void keystore_secure_free(void *ptr, size_t size); - #endif diff --git a/plugins/fishlim/misc.c b/plugins/fishlim/misc.c deleted file mode 100644 index 2b78961d..00000000 --- a/plugins/fishlim/misc.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - - Copyright (c) 2010 Samuel Lidén Borell - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - -*/ - -#include -#include -#include -#include "misc.h" - - -void secure_erase(void *ptr, size_t size) { - // "volatile" prevents this code from being optimized away - volatile char* volptr = ptr; - while (size--) *volptr++ = 0; -} - -/** - * Re-allocates a string with the native allocator. - */ -char *import_glib_string(gchar *gstr) { - size_t size; - char *native; - if (g_mem_is_system_malloc()) return gstr; - - size = strlen(gstr)+1; - native = malloc(size); - memcpy(native, gstr, size); - - secure_erase(gstr, size); - g_free(gstr); - return native; -} - - diff --git a/plugins/fishlim/misc.h b/plugins/fishlim/misc.h deleted file mode 100644 index ee4fc5b8..00000000 --- a/plugins/fishlim/misc.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - - Copyright (c) 2010 Samuel Lidén Borell - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - -*/ - -#ifndef MISC_H -#define MISC_H - -void secure_erase(void *ptr, size_t size); - -#ifdef __G_LIB_H__ -char *import_glib_string(gchar *gstr); -#endif - -#endif - - diff --git a/plugins/fishlim/plugin_hexchat.c b/plugins/fishlim/plugin_hexchat.c index 67866021..82befceb 100644 --- a/plugins/fishlim/plugin_hexchat.c +++ b/plugins/fishlim/plugin_hexchat.c @@ -93,7 +93,7 @@ static int handle_outgoing(char *word[], char *word_eol[], void *userdata) { // Send message hexchat_commandf(ph, "PRIVMSG %s :+OK %s", channel, encrypted); - free(encrypted); + g_free(encrypted); return HEXCHAT_EAT_HEXCHAT; } @@ -180,7 +180,7 @@ static int handle_incoming(char *word[], char *word_eol[], hexchat_event_attrs * g_string_append (message, peice); } - free(decrypted); + g_free(decrypted); // Simulate unencrypted message //hexchat_printf(ph, "simulating: %s\n", message->str); @@ -191,8 +191,8 @@ static int handle_incoming(char *word[], char *word_eol[], hexchat_event_attrs * return HEXCHAT_EAT_HEXCHAT; decrypt_error: - free(decrypted); - free(sender_nick); + g_free(decrypted); + g_free(sender_nick); return HEXCHAT_EAT_NONE; } diff --git a/plugins/fishlim/test.c b/plugins/fishlim/test.c index b4dc8d91..91a9ede1 100644 --- a/plugins/fishlim/test.c +++ b/plugins/fishlim/test.c @@ -47,7 +47,7 @@ static int decrypt(int nick_count, char *nicks[]) { return 1; success: fprintf(stderr, "Decrypted text >>>%s<<<\n", msg); - free(msg); + g_free(msg); } return 0; } @@ -64,7 +64,7 @@ static int encrypt(int nick_count, char *nicks[]) { char *encrypted = fish_encrypt_for_nick(nicks[i], message); if (encrypted) { fprintf(stderr, "Encrypted [%s]: >>>%s<<<\n", nicks[i], encrypted); - free(encrypted); + g_free(encrypted); } else { error = true; } diff --git a/plugins/mpcinfo/functions.c b/plugins/mpcinfo/functions.c index de2e8a40..e5993948 100644 --- a/plugins/mpcinfo/functions.c +++ b/plugins/mpcinfo/functions.c @@ -14,6 +14,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include + char *split(char *text, char separator) { int pos = -1; @@ -67,7 +69,7 @@ int inStr(char *s1, size_t sl1, char *s2) static char *subString(char *text, int first, int length, int spcKill){ //if (DEBUG==1) putlog("creating substring"); - char *ret=(char*) calloc (length+1,sizeof(char)); //malloc(sizeof(char)*(length+1)); + char *ret = g_new (char, length + 1); int i; ret[length]=0; for (i=0;itrue WIN32;NDEBUG;_WINDOWS;_USRDLL;MPCINFO_EXPORTS;%(PreprocessorDefinitions) true - ..\..\src\common;%(AdditionalIncludeDirectories) + ..\..\src\common;$(Glib);%(AdditionalIncludeDirectories) Windows true true true + $(DepsRoot)\lib;%(AdditionalLibraryDirectories) + $(DepLibs);%(AdditionalDependencies) mpcinfo.def @@ -81,13 +83,15 @@ true WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;MPCINFO_EXPORTS;%(PreprocessorDefinitions) true - ..\..\src\common;%(AdditionalIncludeDirectories) + ..\..\src\common;$(Glib);%(AdditionalIncludeDirectories) Windows true true true + $(DepsRoot)\lib;%(AdditionalLibraryDirectories) + $(DepLibs);%(AdditionalDependencies) mpcinfo.def diff --git a/plugins/perl/Makefile.am b/plugins/perl/Makefile.am index 7e7bbe68..bec4e5ce 100644 --- a/plugins/perl/Makefile.am +++ b/plugins/perl/Makefile.am @@ -7,8 +7,8 @@ libdir = $(hexchatlibdir) lib_LTLIBRARIES = perl.la perl_la_SOURCES = perl.c perl_la_LDFLAGS = $(PERL_LDFLAGS) $(PLUGIN_LDFLAGS) -module -perl_la_LIBADD = $(PERL_LIBS) -perl_la_CFLAGS = $(PERL_CFLAGS) -I$(top_srcdir)/src/common +perl_la_LIBADD = $(PERL_LIBS) $(GLIB_LIBS) +perl_la_CFLAGS = $(PERL_CFLAGS) $(GLIB_CFLAGS) -I$(top_srcdir)/src/common BUILT_SOURCES = hexchat.pm.h irc.pm.h CLEANFILES = $(BUILT_SOURCES) diff --git a/plugins/perl/perl.c b/plugins/perl/perl.c index 9bf4f874..b954fb0b 100644 --- a/plugins/perl/perl.c +++ b/plugins/perl/perl.c @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#include "config.h" + #include #include #include @@ -31,8 +33,9 @@ #include #endif +#include + #undef PACKAGE -#include "config.h" #include "hexchat-plugin.h" @@ -75,37 +78,26 @@ thread_mbox (char *str) static void perl_auto_load_from_path (const char *path) { - WIN32_FIND_DATA find_data; - HANDLE find_handle; - char *search_path; - int path_len = strlen (path); - - /* +6 for \*.pl and \0 */ - search_path = malloc(path_len + 6); - sprintf (search_path, "%s\\*.pl", path); - - find_handle = FindFirstFile (search_path, &find_data); + char *search_path = g_build_filename (path, "*.pl", NULL); + WIN32_FIND_DATAA find_data; + HANDLE find_handle = FindFirstFileA (search_path, &find_data); if (find_handle != INVALID_HANDLE_VALUE) { do { - if (!(find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY - ||find_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) + if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 && (find_data.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) { - char *full_path = - malloc (path_len + strlen (find_data.cFileName) + 2); - sprintf (full_path, "%s\\%s", path, find_data.cFileName); - + char *full_path = g_build_filename (path, find_data.cFileName, NULL); perl_load_file (full_path); - free (full_path); + g_free (full_path); } } - while (FindNextFile (find_handle, &find_data) != 0); + while (FindNextFileA (find_handle, &find_data) != 0); FindClose (find_handle); } - free (search_path); + g_free (search_path); } #else static void @@ -115,14 +107,16 @@ perl_auto_load_from_path (const char *path) struct dirent *ent; dir = opendir (path); - if (dir) { - while ((ent = readdir (dir))) { + if (dir) + { + while ((ent = readdir (dir))) + { int len = strlen (ent->d_name); - if (len > 3 && strcasecmp (".pl", ent->d_name + len - 3) == 0) { - char *file = malloc (len + strlen (path) + 2); - sprintf (file, "%s/%s", path, ent->d_name); + if (len > 3 && strcasecmp (".pl", ent->d_name + len - 3) == 0) + { + char *file = g_build_filename (path, ent->d_name, NULL); perl_load_file (file); - free (file); + g_free (file); } } closedir (dir); @@ -145,31 +139,10 @@ perl_auto_load (void *unused) /* don't pollute the filesystem with script files, this only causes misuse of the folders * only use ~/.config/hexchat/addons/ and %APPDATA%\HexChat\addons */ -#if 0 - /* autoload from ~/.config/hexchat/ or %APPDATA%\HexChat\ on win32 */ - perl_auto_load_from_path (xdir); -#endif - - sub_dir = malloc (strlen (xdir) + 8); - strcpy (sub_dir, xdir); - strcat (sub_dir, "/addons"); + sub_dir = g_build_filename (xdir, "addons", NULL); perl_auto_load_from_path (sub_dir); - free (sub_dir); + g_free (sub_dir); -#if 0 -#ifdef WIN32 - /* autoload from C:\Program Files\HexChat\plugins\ */ - sub_dir = malloc (1025 + 9); - copied = GetModuleFileName( 0, sub_dir, 1024 ); - sub_dir[copied] = '\0'; - slash = strrchr( sub_dir, '\\' ); - if( slash != NULL ) { - *slash = '\0'; - } - perl_auto_load_from_path ( strncat (sub_dir, "\\plugins", 9)); - free (sub_dir); -#endif -#endif return 0; } @@ -384,7 +357,7 @@ fd_cb (int fd, int flags, void *userdata) if (data->userdata) { SvREFCNT_dec (data->userdata); } - free (data); + g_free (data); } } @@ -748,7 +721,7 @@ XS (XS_HexChat_send_modes) if (SvROK (ST (0))) { p_targets = (AV*) SvRV (ST (0)); target_count = av_len (p_targets) + 1; - targets = malloc (target_count * sizeof (char *)); + targets = g_new (const char *, target_count); for (i = 0; i < target_count; i++ ) { elem = av_fetch (p_targets, i, 0); @@ -759,13 +732,13 @@ XS (XS_HexChat_send_modes) } } } else{ - targets = malloc (sizeof (char *)); + targets = g_new (const char *, 1); targets[0] = SvPV_nolen (ST (0)); target_count = 1; } if (target_count == 0) { - free ((char**) targets); + g_free ((char**) targets); XSRETURN_EMPTY; } @@ -777,7 +750,7 @@ XS (XS_HexChat_send_modes) } hexchat_send_modes (ph, targets, target_count, modes_per_line, sign, mode); - free ((char**) targets); + g_free ((char**) targets); } } static @@ -895,11 +868,7 @@ XS (XS_HexChat_hook_server) userdata = ST (3); package = ST (4); data = NULL; - data = malloc (sizeof (HookData)); - if (data == NULL) { - XSRETURN_UNDEF; - } - + data = g_new (HookData, 1); data->callback = newSVsv (callback); data->userdata = newSVsv (userdata); data->depth = 0; @@ -944,11 +913,7 @@ XS (XS_HexChat_hook_command) package = ST (5); data = NULL; - data = malloc (sizeof (HookData)); - if (data == NULL) { - XSRETURN_UNDEF; - } - + data = g_new (HookData, 1); data->callback = newSVsv (callback); data->userdata = newSVsv (userdata); data->depth = 0; @@ -984,11 +949,7 @@ XS (XS_HexChat_hook_print) userdata = ST (3); package = ST (4); - data = malloc (sizeof (HookData)); - if (data == NULL) { - XSRETURN_UNDEF; - } - + data = g_new (HookData, 1); data->callback = newSVsv (callback); data->userdata = newSVsv (userdata); data->depth = 0; @@ -1022,11 +983,7 @@ XS (XS_HexChat_hook_timer) userdata = ST (2); package = ST (3); - data = malloc (sizeof (HookData)); - if (data == NULL) { - XSRETURN_UNDEF; - } - + data = g_new (HookData, 1); data->callback = newSVsv (callback); data->userdata = newSVsv (userdata); data->ctx = hexchat_get_context (ph); @@ -1076,11 +1033,7 @@ XS (XS_HexChat_hook_fd) } #endif - data = malloc (sizeof (HookData)); - if (data == NULL) { - XSRETURN_UNDEF; - } - + data = g_new (HookData, 1); data->callback = newSVsv (callback); data->userdata = newSVsv (userdata); data->depth = 0; @@ -1120,7 +1073,7 @@ XS (XS_HexChat_unhook) SvREFCNT_dec (userdata->package); } - free (userdata); + g_free (userdata); } XSRETURN (retCount); } diff --git a/plugins/perl/perl.vcxproj b/plugins/perl/perl.vcxproj index 7ae6da0b..4fd803aa 100644 --- a/plugins/perl/perl.vcxproj +++ b/plugins/perl/perl.vcxproj @@ -62,7 +62,7 @@ true true WIN32;NDEBUG;_WINDOWS;_USRDLL;PERL520_EXPORTS;$(OwnFlags);%(PreprocessorDefinitions) - $(SolutionDir)..;$(PerlPath)\lib\CORE;$(IntDir);..\..\src\common;%(AdditionalIncludeDirectories) + $(SolutionDir)..;$(PerlPath)\lib\CORE;$(IntDir);..\..\src\common;$(Glib);%(AdditionalIncludeDirectories) true @@ -70,8 +70,8 @@ true true true - $(OutDir);%(AdditionalLibraryDirectories) - $(PerlLib).lib;%(AdditionalDependencies) + $(OutDir);$(DepsRoot)\lib;%(AdditionalLibraryDirectories) + $(PerlLib).lib;$(DepLibs);%(AdditionalDependencies) perl.def $(PerlLib).dll;%(DelayLoadDLLs) @@ -91,7 +91,7 @@ move hexchat.pm.h "$(IntDir)" true true WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;PERL520_EXPORTS;$(OwnFlags);%(PreprocessorDefinitions) - $(SolutionDir)..;$(PerlPath)\lib\CORE;$(IntDir);..\..\src\common;%(AdditionalIncludeDirectories) + $(SolutionDir)..;$(PerlPath)\lib\CORE;$(IntDir);..\..\src\common;$(Glib);%(AdditionalIncludeDirectories) true @@ -99,8 +99,8 @@ move hexchat.pm.h "$(IntDir)" true true true - $(OutDir);%(AdditionalLibraryDirectories) - $(PerlLib).lib;%(AdditionalDependencies) + $(OutDir);$(DepsRoot)\lib;%(AdditionalLibraryDirectories) + $(PerlLib).lib;$(DepLibs);%(AdditionalDependencies) perl.def $(PerlLib).dll;%(DelayLoadDLLs) @@ -122,4 +122,4 @@ move hexchat.pm.h "$(IntDir)" - \ No newline at end of file + diff --git a/plugins/python/python.c b/plugins/python/python.c index f0e4aa72..903b2bed 100644 --- a/plugins/python/python.c +++ b/plugins/python/python.c @@ -1407,11 +1407,7 @@ static Hook * Plugin_AddHook(int type, PyObject *plugin, PyObject *callback, PyObject *userdata, char *name, void *data) { - Hook *hook = (Hook *) g_malloc(sizeof(Hook)); - if (hook == NULL) { - PyErr_NoMemory(); - return NULL; - } + Hook *hook = g_new(Hook, 1); hook->type = type; hook->plugin = plugin; Py_INCREF(callback); @@ -2532,11 +2528,8 @@ IInterp_Exec(char *command) } d = PyModule_GetDict(m); len = strlen(command); - buffer = (char *) g_malloc(len+2); - if (buffer == NULL) { - hexchat_print(ph, "Not enough memory for command buffer"); - goto fail; - } + + buffer = g_malloc(len + 2); memcpy(buffer, command, len); buffer[len] = '\n'; buffer[len+1] = 0; diff --git a/plugins/sysinfo/match.c b/plugins/sysinfo/match.c index ae850b5b..5f49ae41 100644 --- a/plugins/sysinfo/match.c +++ b/plugins/sysinfo/match.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "xsys.h" float percentage(unsigned long long *free, unsigned long long *total) @@ -37,13 +38,13 @@ char *pretty_freespace(const char *desc, unsigned long long *free_k, unsigned lo double free_space, total_space; free_space = *free_k; total_space = *total_k; - result = malloc(bsize * sizeof(char)); + result = g_new(char, bsize); if (total_space == 0) { snprintf(result, bsize, "%s: none", desc); return result; } - quantity = quantities; + quantity = quantities; while (total_space > 1023 && *(quantity + 1)) { quantity++; diff --git a/plugins/sysinfo/parse.c b/plugins/sysinfo/parse.c index 6c86c645..caba8a7d 100644 --- a/plugins/sysinfo/parse.c +++ b/plugins/sysinfo/parse.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "pci.h" #include "match.h" @@ -317,13 +318,13 @@ int xs_parse_df(const char *mount_point, char *result) char *tmp_buf = pretty_freespace(pos, &free_k, &total_k); strcat(tmp_buf, " | "); strcat(result, tmp_buf); - free(tmp_buf); + g_free(tmp_buf); } else if(strncmp(mount_point, pos, strlen(mount_point)) == 0) { char *tmp_buf = pretty_freespace(mount_point, &free_k, &total_k); strncpy(result, tmp_buf, bsize); - free(tmp_buf); + g_free(tmp_buf); break; } else snprintf(result, bsize, "Mount point %s not found!", mount_point); @@ -336,7 +337,7 @@ int xs_parse_df(const char *mount_point, char *result) { char *tmp_buf = pretty_freespace("Total", &free_k, &total_k); strncpy(result, tmp_buf, bsize); - free(tmp_buf); + g_free(tmp_buf); } pclose(pipe); return 0; diff --git a/plugins/sysinfo/pci.c b/plugins/sysinfo/pci.c index 9946c446..d0f8d811 100644 --- a/plugins/sysinfo/pci.c +++ b/plugins/sysinfo/pci.c @@ -25,6 +25,8 @@ #include #include #include +#include + #include "xsys.h" static struct pci_filter filter; /* Device filter */ @@ -47,8 +49,7 @@ static struct device *scan_device(struct pci_dev *p) if (!pci_filter_match(&filter, p)) return NULL; - d = malloc(sizeof(struct device)); - bzero(d, sizeof(*d)); + d = g_new0 (struct device, 1); d->dev = p; if (!pci_read_block(p, 0, d->config, how_much)) exit(1); diff --git a/plugins/sysinfo/xsys.c b/plugins/sysinfo/xsys.c index ba02ad46..0c32b751 100644 --- a/plugins/sysinfo/xsys.c +++ b/plugins/sysinfo/xsys.c @@ -162,7 +162,7 @@ print_summary (int announce, char* format) free_space = pretty_freespace ("Physical", &mem_free, &mem_total); snprintf (buffer, bsize, "%s", free_space); - free (free_space); + g_free (free_space); format_output ("RAM", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); -- cgit 1.4.1