There is no need to use a buffer at all.
[oweals/opkg-lede.git] / libopkg / opkg.c
index 9cbbe906c65893ba3a5fa4cfcc6a4a424c089a06..437beb1b8890117ee6c01602ada33f4efbe86b6b 100644 (file)
@@ -162,7 +162,7 @@ opkg_package_new ()
 
   opkg_package_t *p;
 
-  p = calloc (1, sizeof (opkg_package_t));
+  p = xcalloc(1, sizeof (opkg_package_t));
 
   return p;
 }
@@ -187,18 +187,12 @@ opkg_new ()
   opkg_t *opkg;
   int err;
 
-  opkg = calloc (1, sizeof (opkg_t));
+  opkg = xcalloc(1, sizeof (opkg_t));
 
-  opkg->args = calloc (1, sizeof (args_t));
-  err = args_init (opkg->args);
-  if (err)
-  {
-    free (opkg->args);
-    free (opkg);
-    return NULL;
-  }
+  opkg->args = xcalloc(1, sizeof (args_t));
+  args_init (opkg->args);
 
-  opkg->conf = calloc (1, sizeof (opkg_conf_t));
+  opkg->conf = xcalloc(1, sizeof (opkg_conf_t));
   err = opkg_conf_init (opkg->conf, opkg->args);
   if (err)
   {
@@ -217,6 +211,9 @@ opkg_free (opkg_t *opkg)
 {
   opkg_assert (opkg != NULL);
 
+#ifdef HAVE_CURL
+  opkg_curl_cleanup();
+#endif
   opkg_conf_deinit (opkg->conf);
   args_deinit (opkg->args);
   free (opkg->options);
@@ -769,10 +766,8 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
     }
   }
 
-  tmp = xstrdup("/tmp/opkg.XXXXXX");
-
-  if (mkdtemp (tmp) == NULL)
-  {
+  sprintf_alloc(&tmp, "%s/update-XXXXXX", opkg->conf->tmp_dir);
+  if (mkdtemp (tmp) == NULL) {
     /* XXX: Error: could not create temporary file name */
     free (lists_dir);
     free (tmp);
@@ -1043,7 +1038,7 @@ int opkg_repository_accessibility_check(opkg_t *opkg)
   {
     if (strstr(((pkg_src_t *)iter->data)->value, "://") && 
                    index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/')) 
-      stmp = strndup(((pkg_src_t *)iter->data)->value, 
+      stmp = xstrndup(((pkg_src_t *)iter->data)->value, 
                      (index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/') - ((pkg_src_t *)iter->data)->value)*sizeof(char));
 
     else