summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjihye kim <jihye1128.kim@samsung.com>2012-09-05 20:21:11 +0900
committerjihye kim <jihye1128.kim@samsung.com>2012-09-05 20:21:11 +0900
commitaeb937d0c612570df15c59f65ff1c50ed5386981 (patch)
tree22e8702afbf1db56fae6a204e181dd0b652fe70e
parente2aa43290c6cc19ebe356b2773ad46cd43ad532c (diff)
downloaddevice-manager-plugin-emul-aeb937d0c612570df15c59f65ff1c50ed5386981.tar.gz
device-manager-plugin-emul-aeb937d0c612570df15c59f65ff1c50ed5386981.tar.bz2
device-manager-plugin-emul-aeb937d0c612570df15c59f65ff1c50ed5386981.zip
[Title] modify sys_get_str
[Type] bug fix [Module] device-manager-plugin [Priority] major [Jira#] [Redmine#] [Problem] throw memory leak [Cause] they do not freeing memory [Solution] using local memory buffer [TestCase]
-rw-r--r--packaging/device-manager-plugin-maru.spec2
-rw-r--r--src/device_manager_io.c13
-rw-r--r--src/device_manager_plugin_maru.c34
3 files changed, 28 insertions, 21 deletions
diff --git a/packaging/device-manager-plugin-maru.spec b/packaging/device-manager-plugin-maru.spec
index 657e36a..46341d6 100644
--- a/packaging/device-manager-plugin-maru.spec
+++ b/packaging/device-manager-plugin-maru.spec
@@ -1,6 +1,6 @@
Name: device-manager-plugin-maru
Summary: device-manager-plugin-maru
-Version: 0.0.8
+Version: 0.0.9
Release: 1
Group: TO_BE/FILLED_IN
License: TO_BE/FILLED_IN
diff --git a/src/device_manager_io.c b/src/device_manager_io.c
index 00fff4d..3ae0420 100644
--- a/src/device_manager_io.c
+++ b/src/device_manager_io.c
@@ -136,15 +136,16 @@ int sys_get_int(char *fname, int *val)
}
}
-char *sys_get_str(char *fname)
+int sys_get_str(char *fname, char* str)
{
- char buf[BUFF_MAX];
- char *r = NULL;
+ char buf[BUFF_MAX] = {0};
- if (sys_read_buf(fname, buf) == 0)
- r = strdup((char *)buf);
+ if (sys_read_buf(fname, buf) == 0) {
+ strncpy(str, buf, strlen(buf));
+ return 0;
+ }
- return r;
+ return -1;
}
int sys_set_int(char *fname, int val)
diff --git a/src/device_manager_plugin_maru.c b/src/device_manager_plugin_maru.c
index 044e00f..7015590 100644
--- a/src/device_manager_plugin_maru.c
+++ b/src/device_manager_plugin_maru.c
@@ -35,10 +35,12 @@
#define BUFF_MAX 255
#define MAX_NAME 255
+// TODO : checking return value
+#if 0
#define GENERATE_ACCESSORS_CHAR_RW(_suffix, _item) \
-char *OEM_sys_get_##_suffix() \
+char *OEM_sys_get_##_suffix(char* str) \
{ \
- return sys_get_str(_item); \
+ return sys_get_str(_item, str); \
} \
\
int OEM_sys_set_##_suffix(char *str) \
@@ -47,9 +49,9 @@ int OEM_sys_set_##_suffix(char *str) \
}
#define GENERATE_ACCESSORS_CHAR_R(_suffix, _item) \
-char *OEM_sys_get_##_suffix() \
+char *OEM_sys_get_##_suffix(char* str) \
{ \
- return sys_get_str(_item); \
+ return sys_get_str(_item, str); \
}
#define GENERATE_ACCESSORS_CHAR_W(_suffix, _item) \
@@ -57,6 +59,7 @@ int OEM_sys_set_##_suffix(char *str) \
{ \
return sys_set_str(_item, str); \
}
+#endif
/* TODO: Add APIs has (char *) params */
@@ -493,11 +496,12 @@ static char *health_text[] = {
int OEM_sys_get_battery_health(int *value)
{
- char *buf;
- int i = 0;
+ char buf[BUFF_MAX] = {0};
+ int ret = 0;
+ int i = 0;
- buf = sys_get_str(BATTERY_HEALTH_PATH);
- if (NULL == buf) {
+ ret = sys_get_str(BATTERY_HEALTH_PATH, buf);
+ if (ret != 0) {
return -1;
}
@@ -520,10 +524,11 @@ int OEM_sys_get_battery_polling_required(int *value)
int OEM_sys_get_uart_path(int *value)
{
- char *buf;
+ char buf[BUFF_MAX] = {0};
+ int ret = 0;
- buf = sys_get_str(UART_PATH);
- if (NULL == buf) {
+ ret = sys_get_str(UART_PATH, buf);
+ if (ret != 0) {
return -1;
}
@@ -553,10 +558,11 @@ int OEM_sys_set_uart_path(int value)
int OEM_sys_get_usb_path(int *value)
{
- char *buf;
+ char buf[BUFF_MAX] = {0};
+ int ret = 0;
- buf = sys_get_str(USB_PATH);
- if (NULL == buf) {
+ ret = sys_get_str(USB_PATH, buf);
+ if (ret != 0) {
return -1;
}