@@ -112,14 +112,14 @@ void processIssueTypeEvent(data_buf *rbuf)
112112 free (cmdMap [index ]);
113113 cmdMap [index ] = NULL ;
114114 }
115-
115+
116116 }
117117 if ( cmdMap )
118118 {
119119 free (cmdMap );
120120 cmdMap = NULL ;
121121 }
122- }
122+ }
123123 }
124124
125125 RDK_LOG (RDK_LOG_DEBUG , LOG_REMDEBUG , "[%s:%d]: ...Exiting...\n" , __FUNCTION__ , __LINE__ );
@@ -164,31 +164,126 @@ static void processIssueType(data_buf *rbuf)
164164 if (staticprofiledata == NULL )
165165 {
166166 RDK_LOG (RDK_LOG_INFO , LOG_REMDEBUG , "[%s:%d]: Static Command Info not found for IssueType!!! \n" , __FUNCTION__ , __LINE__ );
167+ // Free dynamicprofiledata since we can't proceed
168+ if (dynamicprofiledata != NULL )
169+ {
170+ if (dynamicprofiledata -> rfcvalue != NULL )
171+ {
172+ free (dynamicprofiledata -> rfcvalue );
173+ }
174+ if (dynamicprofiledata -> command != NULL )
175+ {
176+ free (dynamicprofiledata -> command );
177+ }
178+ free (dynamicprofiledata );
179+ }
167180 }
168181 else
169182 {
170183 RDK_LOG (RDK_LOG_INFO , LOG_REMDEBUG , "[%s:%d]: Read complete for Static Profile: RFCValue: %s, Command: %s, Timeout: %d... \n" , __FUNCTION__ , __LINE__ , staticprofiledata -> rfcvalue , staticprofiledata -> command , staticprofiledata -> timeout );
171- //Remove the double quotes
172- size_t staticstrlen = strlen (staticprofiledata -> command );
173- size_t dynamicstrlen = strlen (dynamicprofiledata -> command );
174- if (staticstrlen > 0 && staticprofiledata -> command [staticstrlen - 1 ] == '"' ) {
175- staticprofiledata -> command [staticstrlen - 1 ] = '\0' ;
176- }
177- if (dynamicprofiledata -> command [0 ] == '"' ) {
178- dynamicprofiledata -> command [0 ] = COMMAND_DELIM ;
184+
185+ // Check if commands are NULL before using them
186+ if (dynamicprofiledata -> command == NULL || staticprofiledata -> command == NULL )
187+ {
188+ RDK_LOG (RDK_LOG_ERROR , LOG_REMDEBUG , "[%s:%d]: Command is NULL in dynamic or static profile... \n" , __FUNCTION__ , __LINE__ );
189+ // Free dynamicprofiledata
190+ if (dynamicprofiledata != NULL )
191+ {
192+ if (dynamicprofiledata -> rfcvalue != NULL )
193+ {
194+ free (dynamicprofiledata -> rfcvalue );
195+ }
196+ if (dynamicprofiledata -> command != NULL )
197+ {
198+ free (dynamicprofiledata -> command );
199+ }
200+ free (dynamicprofiledata );
201+ }
202+ // Free staticprofiledata
203+ if (staticprofiledata != NULL )
204+ {
205+ if (staticprofiledata -> rfcvalue != NULL )
206+ {
207+ free (staticprofiledata -> rfcvalue );
208+ }
209+ if (staticprofiledata -> command != NULL )
210+ {
211+ free (staticprofiledata -> command );
212+ }
213+ free (staticprofiledata );
214+ }
179215 }
180- RDK_LOG (RDK_LOG_DEBUG , LOG_REMDEBUG , "[%s:%d]: Static Profile Commands: %s, Dynamic Profile Commands: %s\n" , __FUNCTION__ , __LINE__ , staticprofiledata -> command , dynamicprofiledata -> command );
181-
182- size_t appendstrlen = ((staticstrlen - 1 ) + dynamicstrlen + 1 );
183- char * appendcommandstr = (char * )realloc (staticprofiledata -> command , appendstrlen );
184- if (appendcommandstr == NULL ) {
185- RDK_LOG (RDK_LOG_DEBUG , LOG_REMDEBUG , "[%s:%d]: Memory Allocation Failed... \n" , __FUNCTION__ , __LINE__ );
216+ else
217+ {
218+ //Remove the double quotes
219+ size_t staticstrlen = strlen (staticprofiledata -> command );
220+ size_t dynamicstrlen = strlen (dynamicprofiledata -> command );
221+ if (staticstrlen > 0 && staticprofiledata -> command [staticstrlen - 1 ] == '"' ) {
222+ staticprofiledata -> command [staticstrlen - 1 ] = '\0' ;
223+ staticstrlen -- ; // Update length after removing trailing quote
224+ }
225+ if (dynamicprofiledata -> command [0 ] == '"' ) {
226+ dynamicprofiledata -> command [0 ] = COMMAND_DELIM ;
227+ }
228+ RDK_LOG (RDK_LOG_DEBUG , LOG_REMDEBUG , "[%s:%d]: Static Profile Commands: %s, Dynamic Profile Commands: %s\n" , __FUNCTION__ , __LINE__ , staticprofiledata -> command , dynamicprofiledata -> command );
229+
230+ size_t appendstrlen = (staticstrlen + dynamicstrlen + 1 );
231+ char * appendcommandstr = (char * )realloc (staticprofiledata -> command , appendstrlen );
232+ if (appendcommandstr == NULL ) {
233+ RDK_LOG (RDK_LOG_ERROR , LOG_REMDEBUG , "[%s:%d]: Memory Allocation Failed... \n" , __FUNCTION__ , __LINE__ );
234+ // Free staticprofiledata on realloc failure
235+ if (staticprofiledata != NULL )
236+ {
237+ if (staticprofiledata -> rfcvalue != NULL )
238+ {
239+ free (staticprofiledata -> rfcvalue );
240+ }
241+ if (staticprofiledata -> command != NULL )
242+ {
243+ free (staticprofiledata -> command );
244+ }
245+ free (staticprofiledata );
246+ staticprofiledata = NULL ; // Set to NULL to prevent double-free
247+ }
248+ // Free dynamicprofiledata on realloc failure
249+ if (dynamicprofiledata != NULL )
250+ {
251+ if (dynamicprofiledata -> rfcvalue != NULL )
252+ {
253+ free (dynamicprofiledata -> rfcvalue );
254+ }
255+ if (dynamicprofiledata -> command != NULL )
256+ {
257+ free (dynamicprofiledata -> command );
258+ }
259+ free (dynamicprofiledata );
260+ dynamicprofiledata = NULL ; // Set to NULL to prevent double-free
261+ }
262+ }
263+ else
264+ {
265+ strcat (appendcommandstr , dynamicprofiledata -> command );
266+ staticprofiledata -> command = appendcommandstr ;
267+ RDK_LOG (RDK_LOG_INFO , LOG_REMDEBUG , "[%s:%d]: Updated command after append from dynamic and static profile: %s \n" , __FUNCTION__ , __LINE__ , staticprofiledata -> command );
268+ RDK_LOG (RDK_LOG_DEBUG ,LOG_REMDEBUG ,"[%s:%d]: Executing Commands in Runtime Service... \n" ,__FUNCTION__ ,__LINE__ );
269+ checkIssueNodeInfo (pIssueNode , NULL , rbuf , false, staticprofiledata );
270+ // NOTE: staticprofiledata is freed by executeCommands() via checkIssueNodeInfo()
271+ // Do NOT free staticprofiledata here to avoid double-free
272+ }
273+ // Free dynamicprofiledata after use
274+ if (dynamicprofiledata != NULL )
275+ {
276+ if (dynamicprofiledata -> rfcvalue != NULL )
277+ {
278+ free (dynamicprofiledata -> rfcvalue );
279+ }
280+ if (dynamicprofiledata -> command != NULL )
281+ {
282+ free (dynamicprofiledata -> command );
283+ }
284+ free (dynamicprofiledata );
285+ }
186286 }
187- strcat (appendcommandstr , dynamicprofiledata -> command );
188- staticprofiledata -> command = appendcommandstr ;
189- RDK_LOG (RDK_LOG_INFO , LOG_REMDEBUG , "[%s:%d]: Updated command after append from dynamic and static profile: %s \n" , __FUNCTION__ , __LINE__ , staticprofiledata -> command );
190- RDK_LOG (RDK_LOG_DEBUG ,LOG_REMDEBUG ,"[%s:%d]: Executing Commands in Runtime Service... \n" ,__FUNCTION__ ,__LINE__ );
191- checkIssueNodeInfo (pIssueNode , NULL , rbuf , false, staticprofiledata );
192287 }
193288 }
194289 }
@@ -303,6 +398,8 @@ static void processIssueTypeInStaticProfile(data_buf *rbuf, issueNodeData *pIssu
303398 { // Static Profile JSON Parsing or Read Fail
304399 RDK_LOG (RDK_LOG_ERROR , LOG_REMDEBUG , "[%s:%d]: Static Profile Parse/Read failed... %s\n" , __FUNCTION__ , __LINE__ , RRD_JSON_FILE );
305400 processIssueTypeInInstalledPackage (rbuf , pIssueNode );
401+ RDK_LOG (RDK_LOG_DEBUG , LOG_REMDEBUG , "[%s:%d]: ...Exiting...\n" , __FUNCTION__ , __LINE__ );
402+ return ;
306403 }
307404 RDK_LOG (RDK_LOG_DEBUG , LOG_REMDEBUG , "[%s:%d]: Static Profile Parse And Read Success... %s\n" , __FUNCTION__ , __LINE__ , RRD_JSON_FILE );
308405 RDK_LOG (RDK_LOG_DEBUG , LOG_REMDEBUG , "[%s:%d]: Check if Issue in Parsed Static JSON... %s\n" , __FUNCTION__ , __LINE__ , RRD_JSON_FILE );
0 commit comments