Skip to content

Commit 0116208

Browse files
committed
fix: resolve cppcheck memleakOnRealloc and constParameterPointer warnings
Made-with: Cursor
1 parent 77900a0 commit 0116208

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static bool BarMainLoginUser (BarApp_t *app) {
109109
/* Run a password_command and return the result, or NULL on failure.
110110
* Caller must free the returned string.
111111
*/
112-
static char *BarRunPasswordCommand (BarSettings_t *settings, const char *cmd) {
112+
static char *BarRunPasswordCommand (const BarSettings_t *settings, const char *cmd) {
113113
pid_t chld;
114114
int pipeFd[2];
115115
char passBuf[BAR_INPUT_MAX];
@@ -166,7 +166,7 @@ static char *BarRunPasswordCommand (BarSettings_t *settings, const char *cmd) {
166166
* Sets acct->password if password_command succeeds.
167167
* @return true if password is available after resolution.
168168
*/
169-
static bool BarResolveAccountPassword (BarSettings_t *settings, BarAccount_t *acct) {
169+
static bool BarResolveAccountPassword (const BarSettings_t *settings, BarAccount_t *acct) {
170170
if (acct->password != NULL) return true;
171171
if (acct->passwordCmd != NULL) {
172172
acct->password = BarRunPasswordCommand (settings, acct->passwordCmd);

src/settings.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,11 +771,18 @@ void BarSettingsRead (BarSettings_t *settings) {
771771
char *colon = strchr (val, ':');
772772
if (colon && colon != val && *(colon + 1) != '\0') {
773773
*colon = '\0';
774-
accountLines = realloc (accountLines,
774+
BarAccountLine_t *newLines = realloc (accountLines,
775775
(accountLineCount + 1) * sizeof (BarAccountLine_t));
776-
accountLines[accountLineCount].id = strdup (val);
777-
accountLines[accountLineCount].path = strdup (colon + 1);
778-
accountLineCount++;
776+
if (newLines == NULL) {
777+
BarUiMsg (settings, MSG_ERR,
778+
"Out of memory reading account lines at %s:%zu\n",
779+
path, lineNum);
780+
} else {
781+
accountLines = newLines;
782+
accountLines[accountLineCount].id = strdup (val);
783+
accountLines[accountLineCount].path = strdup (colon + 1);
784+
accountLineCount++;
785+
}
779786
} else {
780787
BarUiMsg (settings, MSG_INFO,
781788
"Invalid account format at %s:%zu (expected id:path)\n",

0 commit comments

Comments
 (0)