Fix the bundle_export_to_argv API 91/72191/2 accepted/tizen/common/20160602.140048 accepted/tizen/ivi/20160602.022853 accepted/tizen/mobile/20160602.023025 accepted/tizen/tv/20160602.022554 accepted/tizen/wearable/20160602.022740 submit/tizen/20160531.024853
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 31 May 2016 06:39:07 +0000 (15:39 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 31 May 2016 07:59:38 +0000 (16:59 +0900)
- Allocate memory for the keys of the bundle

Change-Id: I3daf672cfe9119c572566c44933d1d911e425b8a
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/bundle_internal.h
src/bundle.c

index 633c256..cb4e7de 100755 (executable)
@@ -218,7 +218,6 @@ API bundle *bundle_decode_raw(const bundle_raw *r, const int len);
  * @exception BUNDLE_ERROR_OUT_OF_MEMORY       Out of memory
  * @pre                @a b is a valid bundle object.
  * @post       @a argv is a pointer of newly allocated memory. It must be freed.
- *          Each item of @a argv points to the string in the bundle object @a b. If @a b is freed, @a argv will have garbage pointers. DO NOT FREE @a b BEFORE ACCESSING @a argv!!
  * @see                bundle_import_from_argv()
  @code
  #include <bundle_internal.h>
index dea4736..c49e6ed 100644 (file)
@@ -744,7 +744,7 @@ void _iter_export_to_argv(const char *key, const int type, const keyval_t *kv,
        unsigned char *encoded_byte = NULL;
        size_t byte_len = 0;
 
-       vi->argv[vi->idx] = (char *)key;
+       vi->argv[vi->idx] = strdup(key);
        if (kv->method->encode((struct keyval_t *)kv, &byte, &byte_len) == 0) {
                /* TODO: encode FAILED! */
                BUNDLE_EXCEPTION_PRINT("bundle: FAILED to encode keyval: %s\n",
@@ -806,8 +806,8 @@ int bundle_free_exported_argv(int argc, char ***argv)
        if (!*argv || argc < 2)
                return BUNDLE_ERROR_INVALID_PARAMETER;
 
-       for (i = 3; i < argc; i += 2)
-               free((*argv)[i]); /* need to free value from g_base64_encode() */
+       for (i = 2; i < argc; i++)
+               free((*argv)[i]);
        free(*argv);
        *argv = NULL;