diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/include/semanage/context_record.h new/libsemanage/include/semanage/context_record.h --- old/libsemanage/include/semanage/context_record.h 2005-10-31 11:09:39.000000000 -0500 +++ new/libsemanage/include/semanage/context_record.h 2005-11-02 02:13:39.000000000 -0500 @@ -61,8 +61,9 @@ extern int semanage_context_from_string( const char* str, semanage_context_t** con); -extern char* semanage_context_to_string( +extern int semanage_context_to_string( semanage_handle_t* handle, - semanage_context_t* con); + semanage_context_t* con, + char** str_ptr); #endif diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/context_record.c new/libsemanage/src/context_record.c --- old/libsemanage/src/context_record.c 2005-10-31 11:09:39.000000000 -0500 +++ new/libsemanage/src/context_record.c 2005-11-02 02:11:36.000000000 -0500 @@ -88,9 +88,10 @@ int semanage_context_from_string( return sepol_context_from_string(handle->sepolh, str, con); } -char* semanage_context_to_string( +int semanage_context_to_string( semanage_handle_t* handle, - semanage_context_t* con) { + semanage_context_t* con, + char** str_ptr) { - return sepol_context_to_string(handle->sepolh, con); + return sepol_context_to_string(handle->sepolh, con, str_ptr); } diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/interfaces_file.c new/libsemanage/src/interfaces_file.c --- old/libsemanage/src/interfaces_file.c 2005-11-02 02:04:33.000000000 -0500 +++ new/libsemanage/src/interfaces_file.c 2005-11-02 02:17:15.000000000 -0500 @@ -32,16 +32,14 @@ static int iface_print( if (fprintf(str, "netifcon %s ", name) < 0) goto err; - con_str = semanage_context_to_string(handle, ifcon); - if (!con_str) + if (semanage_context_to_string(handle, ifcon, &con_str) < 0) goto err; if (fprintf(str, "%s", con_str) < 0) goto err; free(con_str); con_str = NULL; - con_str = semanage_context_to_string(handle, msgcon); - if (!con_str) + if (semanage_context_to_string(handle, msgcon, &con_str) < 0) goto err; if (fprintf(str, "%s\n", con_str) < 0) goto err; diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsemanage/src/ports_file.c new/libsemanage/src/ports_file.c --- old/libsemanage/src/ports_file.c 2005-11-02 02:04:33.000000000 -0500 +++ new/libsemanage/src/ports_file.c 2005-11-02 02:17:30.000000000 -0500 @@ -28,6 +28,7 @@ static int port_print( int low = semanage_port_get_low(port); int high = semanage_port_get_high(port); const char* proto = semanage_port_get_proto_str(port); + semanage_context_t* con = semanage_port_get_con(port); if (fprintf(str, "portcon %s ", proto) < 0) goto err; @@ -40,10 +41,8 @@ static int port_print( goto err; } - con_str = semanage_context_to_string(handle, semanage_port_get_con(port)); - if (!con_str) + if (semanage_context_to_string(handle, con, &con_str) < 0) goto err; - if (fprintf(str, "%s\n", con_str) < 0) goto err; diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsepol/include/sepol/context_record.h new/libsepol/include/sepol/context_record.h --- old/libsepol/include/sepol/context_record.h 2005-10-31 11:09:39.000000000 -0500 +++ new/libsepol/include/sepol/context_record.h 2005-11-02 02:10:35.000000000 -0500 @@ -64,8 +64,9 @@ extern int sepol_context_from_string( const char* str, sepol_context_t** con); -extern char* sepol_context_to_string( +extern int sepol_context_to_string( sepol_handle_t* handle, - sepol_context_t* con); + sepol_context_t* con, + char** str_ptr); #endif diff -Naurp --exclude CVS --exclude ChangeLog --exclude VERSION --exclude Makefile old/libsepol/src/context_record.c new/libsepol/src/context_record.c --- old/libsepol/src/context_record.c 2005-10-31 11:09:39.000000000 -0500 +++ new/libsepol/src/context_record.c 2005-11-02 02:14:07.000000000 -0500 @@ -246,21 +246,20 @@ int sepol_context_from_string( return STATUS_ERR; } -char* sepol_context_to_string( +int sepol_context_to_string( sepol_handle_t* handle, - sepol_context_t* con) { + sepol_context_t* con, + char** str_ptr) { + int rc; const int user_sz = strlen(con->user); const int role_sz = strlen(con->role); const int type_sz = strlen(con->type); const int mls_sz = (con->mls)? strlen(con->mls): 0; - const int total_sz = user_sz + role_sz + type_sz + mls_sz + ((con->mls)? 3:2); - char* str = malloc(total_sz + 1); - int rc; - + char* str = (char*) malloc(total_sz + 1); if (!str) goto omem; @@ -281,14 +280,14 @@ char* sepol_context_to_string( } } - return str; + *str_ptr = str; + return STATUS_SUCCESS; omem: ERR(handle, "out of memory"); err: ERR(handle, "could not convert context to string"); - if (str) - free(str); - return NULL; + free(str); + return STATUS_ERR; }