forked from loafle/openapi-generator-original
[C][Client][Clang Static Analyzer] Fix memory leak in apiClient_invoke (#7285)
This commit is contained in:
@@ -300,6 +300,8 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
(char *) listEntry->data);
|
||||
headers = curl_slist_append(headers,
|
||||
buffContent);
|
||||
free(buffContent);
|
||||
buffContent = NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -313,8 +315,8 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
}
|
||||
|
||||
if(formParameters != NULL) {
|
||||
if(strstr(buffContent,
|
||||
"application/x-www-form-urlencoded") != NULL)
|
||||
if(contentType &&
|
||||
findStrInStrList(contentType, "application/x-www-form-urlencoded") != NULL)
|
||||
{
|
||||
long parameterLength = 0;
|
||||
long keyPairLength = 0;
|
||||
@@ -356,7 +358,8 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
curl_easy_setopt(handle, CURLOPT_POSTFIELDS,
|
||||
formString);
|
||||
}
|
||||
if(strstr(buffContent, "multipart/form-data") != NULL) {
|
||||
if(contentType &&
|
||||
findStrInStrList(contentType, "multipart/form-data") != NULL) {
|
||||
mime = curl_mime_init(handle);
|
||||
list_ForEach(listEntry, formParameters) {
|
||||
keyValuePair_t *keyValuePair =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../include/list.h"
|
||||
static listEntry_t *listEntry_create(void *data) {
|
||||
@@ -166,3 +167,19 @@ listEntry_t *list_getElementAt(list_t *list, long indexOfElement) {
|
||||
return currentListEntry;
|
||||
}
|
||||
}
|
||||
|
||||
char* findStrInStrList(list_t *strList, const char *str)
|
||||
{
|
||||
if (!strList || !str) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
listEntry_t* listEntry = NULL;
|
||||
list_ForEach(listEntry, strList) {
|
||||
if (strstr((char*)listEntry->data, str) != NULL) {
|
||||
return (char*)listEntry->data;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -36,4 +36,6 @@ void list_iterateThroughListBackward(list_t* list, void (*operationToPerform)(li
|
||||
|
||||
void listEntry_printAsInt(listEntry_t* listEntry, void *additionalData);
|
||||
void listEntry_free(listEntry_t *listEntry, void *additionalData);
|
||||
|
||||
char* findStrInStrList(list_t* strList, const char* str);
|
||||
#endif // INCLUDE_LIST_H
|
||||
|
||||
@@ -36,4 +36,6 @@ void list_iterateThroughListBackward(list_t* list, void (*operationToPerform)(li
|
||||
|
||||
void listEntry_printAsInt(listEntry_t* listEntry, void *additionalData);
|
||||
void listEntry_free(listEntry_t *listEntry, void *additionalData);
|
||||
|
||||
char* findStrInStrList(list_t* strList, const char* str);
|
||||
#endif // INCLUDE_LIST_H
|
||||
|
||||
@@ -254,6 +254,8 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
(char *) listEntry->data);
|
||||
headers = curl_slist_append(headers,
|
||||
buffContent);
|
||||
free(buffContent);
|
||||
buffContent = NULL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -267,8 +269,8 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
}
|
||||
|
||||
if(formParameters != NULL) {
|
||||
if(strstr(buffContent,
|
||||
"application/x-www-form-urlencoded") != NULL)
|
||||
if(contentType &&
|
||||
findStrInStrList(contentType, "application/x-www-form-urlencoded") != NULL)
|
||||
{
|
||||
long parameterLength = 0;
|
||||
long keyPairLength = 0;
|
||||
@@ -310,7 +312,8 @@ void apiClient_invoke(apiClient_t *apiClient,
|
||||
curl_easy_setopt(handle, CURLOPT_POSTFIELDS,
|
||||
formString);
|
||||
}
|
||||
if(strstr(buffContent, "multipart/form-data") != NULL) {
|
||||
if(contentType &&
|
||||
findStrInStrList(contentType, "multipart/form-data") != NULL) {
|
||||
mime = curl_mime_init(handle);
|
||||
list_ForEach(listEntry, formParameters) {
|
||||
keyValuePair_t *keyValuePair =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../include/list.h"
|
||||
static listEntry_t *listEntry_create(void *data) {
|
||||
@@ -166,3 +167,19 @@ listEntry_t *list_getElementAt(list_t *list, long indexOfElement) {
|
||||
return currentListEntry;
|
||||
}
|
||||
}
|
||||
|
||||
char* findStrInStrList(list_t *strList, const char *str)
|
||||
{
|
||||
if (!strList || !str) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
listEntry_t* listEntry = NULL;
|
||||
list_ForEach(listEntry, strList) {
|
||||
if (strstr((char*)listEntry->data, str) != NULL) {
|
||||
return (char*)listEntry->data;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user