Pass lua_State arg to l_quvi_object_opts_croak_if_error
[libquvi.git] / src / api / free.c
blobf06dfedb357ec234ea20c43c31c5e8448e917601
1 /* libquvi
2 * Copyright (C) 2012-2013 Toni Gundogdu <legatvs@gmail.com>
4 * This file is part of libquvi <http://quvi.sourceforge.net/>.
6 * This library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU Affero General Public
8 * License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General
17 * Public License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
21 /** @file free.c */
23 #include "config.h"
25 #include <lualib.h>
26 #include <proxy.h>
27 #include <glib.h>
29 #include "quvi.h"
30 /* -- */
31 #include "_quvi_s.h"
32 #include "_quvi_script_s.h"
33 /* -- */
34 #include "misc/script_free.h"
35 #include "misc/slst.h"
37 /** @cond NODOC */
38 extern void c_close(_quvi_t);
39 /** @endcond */
41 /** @brief Free all of memory used by a library handle
42 @note If handle is NULL the function simply returns
43 @sa @ref getting_started
44 @ingroup lib
46 void quvi_free(quvi_t handle)
48 _quvi_t q = (_quvi_t) handle;
50 if (handle == NULL)
51 return;
53 c_close(q);
55 /* Strings. */
57 g_string_free(q->status.errmsg, TRUE);
58 q->status.errmsg = NULL;
60 /* Scripts. */
62 m_slist_free_full(q->scripts.subtitle_export, m_script_free);
63 q->scripts.subtitle_export = NULL;
65 m_slist_free_full(q->scripts.subtitle, m_script_free);
66 q->scripts.subtitle = NULL;
68 m_slist_free_full(q->scripts.playlist, m_script_free);
69 q->scripts.playlist = NULL;
71 m_slist_free_full(q->scripts.media, m_script_free);
72 q->scripts.media = NULL;
74 m_slist_free_full(q->scripts.scan, m_script_free);
75 q->scripts.scan = NULL;
77 m_slist_free_full(q->scripts.util, m_script_free);
78 q->scripts.util = NULL;
80 /* Handles. */
82 if (q->handle.lua != NULL)
84 lua_close(q->handle.lua);
85 q->handle.lua = NULL;
88 if (q->handle.proxy != NULL)
90 px_proxy_factory_free(q->handle.proxy);
91 q->handle.proxy = NULL;
94 g_free(q);
95 q = NULL;
98 /* vim: set ts=2 sw=2 tw=72 expandtab: */