@@ -217,25 +217,19 @@ static char *get_first_runpath(const char *runpath) {
217217 if (runpath1 == NULL )
218218 return NULL ;
219219 // runpath is not empty, so strtok shouldn't return NULL when first call.
220- return strdup (strtok (runpath1 , ":" ));
220+ char * tmp = strtok (runpath1 , ":" );
221+ if (!strcmp (tmp , "$ORIGIN" )) {
222+ return get_origin ();
223+ } else {
224+ return strdup (tmp );
225+ }
221226}
222227
223228static char * get_driver_path () {
224- char * LPAC_DRIVER_HOME = get_first_runpath (get_runpath ());
229+ _cleanup_free_ char * LPAC_DRIVER_HOME = get_first_runpath (get_runpath ());
225230 if (LPAC_DRIVER_HOME == NULL )
226231 return NULL ;
227- if (!strcmp (LPAC_DRIVER_HOME , "$ORIGIN" )) {
228- free (LPAC_DRIVER_HOME );
229- LPAC_DRIVER_HOME = get_origin ();
230- if (LPAC_DRIVER_HOME == NULL )
231- return NULL ;
232- }
233- char * tmp = realloc (LPAC_DRIVER_HOME , strlen (LPAC_DRIVER_HOME ) + 8 + 1 );
234- if (tmp == NULL )
235- return NULL ;
236- LPAC_DRIVER_HOME = tmp ;
237- strcat (LPAC_DRIVER_HOME , "/drivers" );
238- return LPAC_DRIVER_HOME ;
232+ return path_concat (LPAC_DRIVER_HOME , "drivers" );
239233}
240234
241235static const struct euicc_driver * find_driver_by_path (const char * restrict dir , char * restrict name ) {
@@ -324,17 +318,6 @@ static const struct euicc_driver *find_driver_by_name(const enum euicc_driver_ty
324318 _cleanup_free_ char * LPAC_DRIVER_HOME = get_driver_path ();
325319 if (LPAC_DRIVER_HOME == NULL )
326320 return false;
327- if (!strcmp (LPAC_DRIVER_HOME , "$ORIGIN" )) {
328- free (LPAC_DRIVER_HOME );
329- LPAC_DRIVER_HOME = get_origin ();
330- if (LPAC_DRIVER_HOME == NULL )
331- return false;
332- }
333- char * tmp = realloc (LPAC_DRIVER_HOME , strlen (LPAC_DRIVER_HOME ) + 8 + 1 );
334- if (tmp == NULL )
335- return NULL ;
336- LPAC_DRIVER_HOME = tmp ;
337- strcat (LPAC_DRIVER_HOME , "/drivers" );
338321
339322 size_t driver_name_len = 7 + strlen (driver_type ) + 1 + strlen (name ) + strlen (dynlib_suffix ) + 1 ;
340323 _cleanup_free_ char * driver_name = calloc (driver_name_len , sizeof (char ));
0 commit comments