Skip to content

Commit

Permalink
Plug leaks
Browse files Browse the repository at this point in the history
Release memory allocated by regcomp
Fix leaks reported by LLVM static analysis in HaikuArchives#47
  • Loading branch information
lonemadmax committed Jan 23, 2023
1 parent 28a9be6 commit b229ad3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
16 changes: 10 additions & 6 deletions source/Station.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ Station::Probe()
{
BHttpHeaders headers;
BMallocIO* buffer;
BUrl* resolvedUrl = new BUrl();
BString contentType("audio/*");

// If source URL is a playlist, retrieve the actual stream URL
Expand Down Expand Up @@ -291,13 +290,13 @@ Station::Probe()
buffer = HttpUtils::GetAll(fStreamUrl, &headers, 2 * 1000 * 1000,
&contentType, 4096);
} else {
status_t resolveStatus = HttpUtils::CheckPort(fStreamUrl, resolvedUrl);
BUrl resolvedUrl;
status_t resolveStatus = HttpUtils::CheckPort(fStreamUrl, &resolvedUrl);
if (resolveStatus != B_OK)
return B_ERROR;

buffer = HttpUtils::GetAll(
*resolvedUrl, &headers, 2 * 1000 * 1000, &contentType, 4096);
delete resolvedUrl;
resolvedUrl, &headers, 2 * 1000 * 1000, &contentType, 4096);
}

#ifdef DEBUGGING
Expand Down Expand Up @@ -566,6 +565,7 @@ Station::RegFind(const char* text, const char* pattern)
match = strndup(text + matchBuffer[1].rm_so,
matchBuffer[1].rm_eo - matchBuffer[1].rm_so);
}
regfree(&patternBuffer);

return match;
}
Expand Down Expand Up @@ -641,12 +641,16 @@ Station::LoadIndirectUrl(BString& shoutCastUrl)
dataIO->Write(&"", 1);
body = (char*) dataIO->Buffer();
char* title = RegFind(body, patternTitle);
if (title != NULL)
if (title != NULL) {
station->fName.SetTo(title);
free(title);
}

char* icon = RegFind(body, patternIcon);
if (icon != NULL)
if (icon != NULL) {
finalUrl.SetPath(BString(icon));
free(icon);
}

contentType = "image/*";

Expand Down
1 change: 1 addition & 0 deletions source/StreamIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ StreamIO::_ProcessMeta()

text += matches[0].rm_eo;
}
regfree(&regex);

fMetaListener->PostMessage(msg);
}

0 comments on commit b229ad3

Please sign in to comment.