# HG changeset patch # User Matti Hamalainen # Date 1587944728 -10800 # Node ID 84d7b33c4e83e8400c843ea19a80354ceb756942 # Parent 11eb7c30889edf8441057cabc94ef098a38eaa5f Change how --help option is handled, and plug some memory leaks in configuration handling. diff -r 11eb7c30889e -r 84d7b33c4e83 main.c --- a/main.c Tue Mar 10 17:01:22 2020 +0200 +++ b/main.c Mon Apr 27 02:45:28 2020 +0300 @@ -92,7 +92,8 @@ optDebug = FALSE, optLogEnable = FALSE, optLogDaily = FALSE, - optOnlyFriendPrv = FALSE; + optOnlyFriendPrv = FALSE, + optShowHelp = FALSE; char *setHomeDir = NULL, *setConfigDir = NULL, *setProxyURI = NULL; th_llist_t *setIgnoreList = NULL, @@ -294,8 +295,7 @@ switch (optN) { case 0: - argShowHelp(); - exit(0); + optShowHelp = TRUE; break; case 1: @@ -1942,6 +1942,21 @@ } +void nn_cfg_free(th_cfgitem_t *node) +{ + switch (node->type) + { + case ITEM_STRING: + th_free(*(node->v.val_str)); + break; + + case ITEM_STRING_LIST: + th_llist_free_func_data(*(node->v.list), th_free); + break; + } +} + + int main(int argc, char *argv[]) { char *tmpStr; @@ -2072,9 +2087,14 @@ optNickSep = optNickSepStr ? optNickSepStr[0] : SET_NICK_SEPARATOR; - setBrowser = getenv("BROWSER"); - if (setBrowser == NULL || setBrowser[0] == 0) - setBrowser = "firefox"; + if (setBrowser == NULL) + { + setBrowser = getenv("BROWSER"); + if (setBrowser == NULL || setBrowser[0] == 0) + setBrowser = "firefox"; + + setBrowser = th_strdup(setBrowser); + } if (optLogPath == NULL && setHomeDir != NULL) { @@ -2126,18 +2146,24 @@ if (optUserNameCmd != NULL) { THMSG(1, "Username set on commandline.\n"); - optUserName = optUserNameCmd; - optPassword = optPasswordCmd; + th_pstr_cpy(&optUserName, optUserNameCmd); + th_pstr_cpy(&optPassword, optPasswordCmd); } if (!argsOK) - return -2; + goto err_exit; + + if (optShowHelp) + { + argShowHelp(); + goto err_exit; + } // Allocate userhash if ((nnUsers = nn_userhash_new()) == NULL) { THERR("Could not allocate userhash. Fatal error.\n"); - return -105; + goto err_exit; } // If no idle messages are set, add default @@ -2355,13 +2381,13 @@ th_free(tmp); } - th_cfg_free(cfg); th_free(setHomeDir); th_free(setConfigDir); - th_llist_free_func_data(setIdleMessages, th_free); nn_userhash_free(nnUsers); nn_editbuf_free(editBuf); + th_cfg_free(cfg, nn_cfg_free); + for (index = 0; index <= SET_MAX_HISTORY; index++) nn_editbuf_free(editHistBuf[index]);