summaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-05-22 15:12:11 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-05-24 16:31:22 +0200
commit06054f68c5d5ca216f2756e7de2787a7ea2b9488 (patch)
tree45332bf88713260528cd8807180d14c796dd0d68 /lib/4a-hal-utilities
parent701bea793ed1d2e20d036957268a71973c975cda (diff)
Add forgotten verifications of allocation results
Concern several types of allocation such as : - malloc/calloc - json_object_new_* - wrap_json_pack - strdup BUG-AGL: SPEC-2329 Change-Id: Iffe2a6a44ef4df2ed0ec4d159682159db5e78cfb Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'lib/4a-hal-utilities')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
index 550faaa..c38bfdd 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
@@ -43,7 +43,7 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
struct HalData *currentHalData;
struct InternalHalMixerData *currentMixerData = NULL;
- json_object *requestJson, *responseJ = NULL, *toReturnJ = NULL;
+ json_object *requestJson, *responseJ = NULL, *toReturnJ = NULL, *verboseBooleanJ;
apiHandle = afb_req_get_api(request);
if(! apiHandle) {
@@ -69,8 +69,17 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
return;
}
- if(json_object_is_type(requestJson, json_type_object) && json_object_get_object(requestJson)->count > 0)
- json_object_object_add(requestJson, "verbose", json_object_new_boolean(1));
+ if(json_object_is_type(requestJson, json_type_object) && json_object_get_object(requestJson)->count > 0) {
+ verboseBooleanJ = json_object_new_boolean(1);
+ if(! verboseBooleanJ) {
+ afb_req_fail(request,
+ "verbose_boolean_allocation",
+ "Didn't succeed to allocate verbose value json boolean");
+ return;
+ }
+
+ json_object_object_add(requestJson, "verbose", verboseBooleanJ);
+ }
apiToCall = currentHalData->internalHalData->mixerApiName;
if(! apiToCall) {
@@ -99,6 +108,12 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
case ACTION_ON_MIXER_ALL_STREAM:
count = (int) HalUtlGetNumberOfMixerDataInList(&currentMixerData);
toReturnJ = json_object_new_object();
+ if(! toReturnJ) {
+ afb_req_fail(request,
+ "response_json_object",
+ "Didn't succeed to allocate response json object");
+ return;
+ }
break;
default:
@@ -237,6 +252,8 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
char *verbToCall,
char *streamCardId)
{
+ int wrapRet;
+
json_object *streamAddedEventJ;
CtlConfigT *ctrlConfig;
@@ -290,11 +307,16 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
return NULL;
}
- wrap_json_pack(&streamAddedEventJ,
- "{s:s, s:s, s:s}",
- "action", "added",
- "name", createdStreamData->verb,
- "cardId", createdStreamData->streamCardId);
+ wrapRet = wrap_json_pack(&streamAddedEventJ,
+ "{s:s, s:s, s:s}",
+ "action", "added",
+ "name", createdStreamData->verb,
+ "cardId", createdStreamData->streamCardId);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,"Didn't succeed to allocate added stream event json object");
+ HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, createdStreamData);
+ return NULL;
+ }
afb_event_push(currentHalData->internalHalData->streamUpdates, streamAddedEventJ);
@@ -306,7 +328,7 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
char *verbToCall,
char *streamCardId)
{
- int returnedErr = 0;
+ int returnedErr = 0, wrapRet;
json_object *streamRemovedEventJ;
@@ -334,12 +356,6 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
if(! toRemoveStreamData)
return -4;
- wrap_json_pack(&streamRemovedEventJ,
- "{s:s, s:s, s:s}",
- "action", "removed",
- "name", toRemoveStreamData->verb,
- "cardId", toRemoveStreamData->streamCardId);
-
if(afb_api_del_verb(apiHandle, verb, NULL)) {
AFB_API_ERROR(apiHandle,"Error while deleting verb for stream : '%s'", verb);
json_object_put(streamRemovedEventJ);
@@ -353,6 +369,16 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
return -6;
}
+ wrapRet = wrap_json_pack(&streamRemovedEventJ,
+ "{s:s, s:s, s:s}",
+ "action", "removed",
+ "name", toRemoveStreamData->verb,
+ "cardId", toRemoveStreamData->streamCardId);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle,"Didn't succeed to allocate removed stream event json object");
+ return -7;
+ }
+
afb_event_push(currentHalData->internalHalData->streamUpdates, streamRemovedEventJ);
return 0;