tizen-platform-wrapper: fix resource leak
[platform/core/system/tizen-platform-wrapper.git] / src / isadmin.c
index 903ebe2..f62a449 100644 (file)
 #include "tzplatform_variables.h"
 #include "tzplatform_config.h"
 
-int _is_admin_static_(uid_t uid) {
+int _has_system_group_static_(uid_t uid) {
        
-       struct passwd *userinfo = NULL;
-       struct group *systemgroupinfo = NULL;
+       struct passwd pwd, *userinfo = NULL;
+       struct group grp, *systemgroupinfo = NULL;
        const char *sysgrpname = NULL;
+       char buf[1024];
        uid_t myuid = 0;
        gid_t system_gid = 0;
        gid_t *groups = NULL;
@@ -63,7 +64,7 @@ int _is_admin_static_(uid_t uid) {
                fprintf( stderr, "isadmin ERROR: variable TZ_SYS_ADMIN_GROUP is NULL");
                return -1;
        }
-       systemgroupinfo = getgrnam(sysgrpname);
+       getgrnam_r(sysgrpname, &grp, buf, sizeof(buf), &systemgroupinfo);
        if(systemgroupinfo == NULL) {
                fprintf( stderr, "isadmin ERROR: cannot find group named \"%s\"\n", sysgrpname);
                return -1;
@@ -73,7 +74,7 @@ int _is_admin_static_(uid_t uid) {
        
        /* Get all the gid of the given uid */
        
-       userinfo = getpwuid(myuid);
+       getpwuid_r(myuid, &pwd, buf, sizeof(buf), &userinfo);
        
        /* Need to call this function now to get the number of group to make the
           malloc correctly sized */