mirror of
https://github.com/rsyslog/rsyslog.git
synced 2025-12-17 04:40:43 +01:00
Merge pull request #6002 from rgerhards/statan2
mmaitag: fix potential memory leak
This commit is contained in:
commit
3e64f45bb8
@ -75,10 +75,10 @@ static rsRetVal gemini_classify_batch(ai_provider_t *prov, const char **messages
|
|||||||
const char *mock = getenv("GEMINI_MOCK_RESPONSE");
|
const char *mock = getenv("GEMINI_MOCK_RESPONSE");
|
||||||
(void)prov;
|
(void)prov;
|
||||||
(void)messages;
|
(void)messages;
|
||||||
char *tmp;
|
char *tmp = NULL;
|
||||||
char *tok;
|
char *tok = NULL;
|
||||||
char *saveptr = NULL;
|
char *saveptr = NULL;
|
||||||
char **out;
|
char **out = NULL;
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
DEFiRet;
|
DEFiRet;
|
||||||
|
|
||||||
@ -96,21 +96,29 @@ static rsRetVal gemini_classify_batch(ai_provider_t *prov, const char **messages
|
|||||||
for (size_t i = 0; i < next && tok != NULL; ++i) tok = strtok_r(NULL, ",", &saveptr);
|
for (size_t i = 0; i < next && tok != NULL; ++i) tok = strtok_r(NULL, ",", &saveptr);
|
||||||
|
|
||||||
CHKmalloc(out = calloc(n, sizeof(char *)));
|
CHKmalloc(out = calloc(n, sizeof(char *)));
|
||||||
|
|
||||||
for (idx = 0; idx < n; ++idx) {
|
for (idx = 0; idx < n; ++idx) {
|
||||||
if (tok != NULL) {
|
if (tok != NULL) {
|
||||||
out[idx] = strdup(tok);
|
CHKmalloc(out[idx] = strdup(tok));
|
||||||
tok = strtok_r(NULL, ",", &saveptr);
|
tok = strtok_r(NULL, ",", &saveptr);
|
||||||
} else {
|
} else {
|
||||||
// Fallback if we run out of mock tags
|
// Fallback if we run out of mock tags
|
||||||
out[idx] = strdup("REGULAR");
|
CHKmalloc(out[idx] = strdup("REGULAR"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next += n; // Update state for the next call
|
next += n; // Update state for the next call
|
||||||
|
|
||||||
free(tmp);
|
|
||||||
*tags = out;
|
*tags = out;
|
||||||
|
out = NULL;
|
||||||
|
|
||||||
finalize_it:
|
finalize_it:
|
||||||
|
if (out != NULL) {
|
||||||
|
for (idx = 0; idx < n; ++idx) {
|
||||||
|
free(out[idx]);
|
||||||
|
}
|
||||||
|
free(out);
|
||||||
|
}
|
||||||
|
free(tmp);
|
||||||
RETiRet;
|
RETiRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user