Commit 45d3dd4b authored by Derk-Jan Hartman's avatar Derk-Jan Hartman Committed by Jean-Baptiste Kempf

macosx preferences: more memleaks

* initmethods returning nil. checks moved outside init.
* leaking module_config_get. Keep better track of those.
* spurious strdup
* leaked hotkeys NSMutableArray when resetting the preferences.
(cherry picked from commit 27d841889c9116d46be643fa482f9ca562d233f3)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 262f762d
......@@ -66,17 +66,13 @@
NSMutableArray *_children;
NSMutableArray *_options;
NSMutableArray *_subviews;
module_config_t * _configItem;
}
- (id)initWithConfigItem:(module_config_t *)configItem;
- (id)initWithName:(NSString*)name andConfigItem:(module_config_t *)configItem;
- (id)initWithName:(NSString*)name;
- (int)numberOfChildren;
- (VLCTreeItem *)childAtIndex:(int)i_index;
- (module_config_t *)configItem;
- (NSString *)name;
- (NSMutableArray *)children;
- (NSMutableArray *)options;
......@@ -99,9 +95,14 @@
/* Plugin daughters */
@interface VLCTreePluginItem : VLCTreeItem
{
module_config_t * _configItems;
unsigned int _configSize;
}
+ (VLCTreePluginItem *)pluginTreeItemWithPlugin:(module_t *)plugin;
- (id)initWithPlugin:(module_t *)plugin;
- (module_config_t *)configItems;
- (unsigned int)configSize;
@end
/* CONFIG_CAT */
......@@ -111,18 +112,23 @@
}
+ (VLCTreeCategoryItem *)categoryTreeItemWithCategory:(int)category;
- (id)initWithCategory:(int)category;
- (int)category;
- (VLCTreeSubCategoryItem *)itemRepresentingSubCategory:(int)category;
@end
/* individual options. */
@interface VLCTreeLeafItem : VLCTreeItem
{ }
{
module_config_t * _configItem;
}
- (id)initWithConfigItem:(module_config_t *)configItem;
- (module_config_t *)configItem;
@end
@interface VLCTreeMainItem : VLCTreeItem
@interface VLCTreeMainItem : VLCTreePluginItem
{
module_config_t * _configItems;
}
- (VLCTreeCategoryItem *)itemRepresentingCategory:(int)category;
@end
......@@ -298,12 +304,6 @@ static VLCPrefs *_o_sharedMainInstance = nil;
return nil;
}
- (void)dealloc
{
module_config_free( _configItems );
[super dealloc];
}
- (bool)isSubCategoryGeneral:(int)category
{
if(category == SUBCAT_VIDEO_GENERAL ||
......@@ -337,34 +337,44 @@ static VLCPrefs *_o_sharedMainInstance = nil;
/* Add the capabilities */
for( i = 0; i < count; i++ )
{
module_t * p_module = modules[i];
/* Exclude empty plugins (submodules don't have config */
/* options, they are stored in the parent module) */
unsigned int confsize;
_configItems = module_config_get( p_module, &confsize );
VLCTreeCategoryItem * categoryItem = nil;
VLCTreeSubCategoryItem * subCategoryItem = nil;
VLCTreePluginItem * pluginItem = nil;
module_config_t *p_configs = NULL;
int lastsubcat = 0;
unsigned int confsize;
module_t * p_module = modules[i];
/* Exclude empty plugins (submodules don't have config */
/* options, they are stored in the parent module) */
if( module_is_main( p_module) )
{
pluginItem = self;
_configItems = module_config_get( p_module, &confsize );
_configSize = confsize;
} else {
pluginItem = [VLCTreePluginItem pluginTreeItemWithPlugin: p_module];
confsize = [pluginItem configSize];
}
p_configs = [pluginItem configItems];
unsigned int j;
for( j = 0; j < confsize; j++ )
{
int configType = _configItems[j].i_type;
int configType = p_configs[j].i_type;
if( configType == CONFIG_CATEGORY )
{
categoryItem = [self itemRepresentingCategory:_configItems[j].value.i];
categoryItem = [self itemRepresentingCategory:p_configs[j].value.i];
if(!categoryItem)
{
categoryItem = [VLCTreeCategoryItem categoryTreeItemWithCategory:_configItems[j].value.i];
categoryItem = [VLCTreeCategoryItem categoryTreeItemWithCategory:p_configs[j].value.i];
if(categoryItem) [[self children] addObject:categoryItem];
}
}
else if( configType == CONFIG_SUBCATEGORY )
{
lastsubcat = _configItems[j].value.i;
lastsubcat = p_configs[j].value.i;
if( categoryItem && ![self isSubCategoryGeneral:lastsubcat] )
{
subCategoryItem = [categoryItem itemRepresentingSubCategory:lastsubcat];
......@@ -380,22 +390,21 @@ static VLCPrefs *_o_sharedMainInstance = nil;
{
if( categoryItem && [self isSubCategoryGeneral:lastsubcat] )
{
[[categoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&_configItems[j]]];
[[categoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&p_configs[j]]];
}
else if( subCategoryItem )
{
[[subCategoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&_configItems[j]]];
[[subCategoryItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&p_configs[j]]];
}
}
else if( !module_is_main( p_module) && (configType & CONFIG_ITEM))
{
if( !pluginItem )
if( ![[subCategoryItem children] containsObject: pluginItem] )
{
pluginItem = [VLCTreePluginItem pluginTreeItemWithPlugin: p_module];
if(pluginItem) [[subCategoryItem children] addObject:pluginItem];
[[subCategoryItem children] addObject:pluginItem];
}
if( pluginItem )
[[pluginItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&_configItems[j]]];
[[pluginItem options] addObject:[[VLCTreeLeafItem alloc] initWithConfigItem:&p_configs[j]]];
}
}
}
......@@ -408,13 +417,13 @@ static VLCPrefs *_o_sharedMainInstance = nil;
@implementation VLCTreeCategoryItem
+ (VLCTreeCategoryItem *)categoryTreeItemWithCategory:(int)category
{
if(!config_CategoryNameGet( category )) return nil;
return [[[[self class] alloc] initWithCategory:category] autorelease];
}
- (id)initWithCategory:(int)category
{
if(!config_CategoryNameGet( category )) return nil;
NSString * name = [[VLCMain sharedInstance] localizedString: config_CategoryNameGet( category )];
if(self = [super initWithName:name andConfigItem:nil])
if(self = [super initWithName:name])
{
_category = category;
//_help = [[[VLCMain sharedInstance] localizedString: config_CategoryHelpGet( category )] retain];
......@@ -444,9 +453,8 @@ static VLCPrefs *_o_sharedMainInstance = nil;
@implementation VLCTreeSubCategoryItem
- (id)initWithSubCategory:(int)subCategory
{
if(!config_CategoryNameGet( subCategory )) return nil;
NSString * name = [[VLCMain sharedInstance] localizedString: config_CategoryNameGet( subCategory )];
if(self = [super initWithName:name andConfigItem:NULL])
if(self = [super initWithName:name])
{
_subCategory = subCategory;
//_help = [[[VLCMain sharedInstance] localizedString: config_CategoryHelpGet( subCategory )] retain];
......@@ -456,6 +464,7 @@ static VLCPrefs *_o_sharedMainInstance = nil;
+ (VLCTreeSubCategoryItem *)subCategoryTreeItemWithSubCategory:(int)subCategory
{
if(!config_CategoryNameGet( subCategory )) return nil;
return [[[[self class] alloc] initWithSubCategory:subCategory] autorelease];
}
......@@ -470,9 +479,10 @@ static VLCPrefs *_o_sharedMainInstance = nil;
@implementation VLCTreePluginItem
- (id)initWithPlugin:(module_t *)plugin
{
NSString * name = [[VLCMain sharedInstance] localizedString: module_get_name( plugin, false )];
if(self = [super initWithName:name andConfigItem:NULL])
NSString * name = [[VLCMain sharedInstance] localizedString: module_get_name( plugin, false )?:""];
if(self = [super initWithName:name])
{
_configItems = module_config_get( plugin, &_configSize );
//_plugin = plugin;
//_help = [[[VLCMain sharedInstance] localizedString: config_CategoryHelpGet( subCategory )] retain];
}
......@@ -484,29 +494,54 @@ static VLCPrefs *_o_sharedMainInstance = nil;
return [[[[self class] alloc] initWithPlugin:plugin] autorelease];
}
- (void)dealloc
{
module_config_free( _configItems );
[super dealloc];
}
- (module_config_t *)configItems
{
return _configItems;
}
- (unsigned int)configSize
{
return _configSize;
}
@end
#pragma mark -
@implementation VLCTreeLeafItem
- (id)initWithConfigItem: (module_config_t *) configItem
{
NSString * name = [[[VLCMain sharedInstance] localizedString:configItem->psz_name] autorelease];
self = [super initWithName:name];
if( self != nil )
{
_configItem = configItem;
}
return self;
}
- (module_config_t *)configItem
{
return _configItem;
}
@end
#pragma mark -
#pragma mark (Root class for all TreeItems)
@implementation VLCTreeItem
- (id)initWithConfigItem: (module_config_t *) configItem
{
NSString * name = [[VLCMain sharedInstance] localizedString:configItem->psz_name];
return [self initWithName:name andConfigItem:configItem];
}
- (id)initWithName:(NSString*)name andConfigItem:(module_config_t *)configItem
- (id)initWithName:(NSString*)name
{
self = [super init];
if( self != nil )
{
_name = [name retain];
_configItem = configItem;
}
return self;
}
......@@ -552,7 +587,7 @@ static VLCPrefs *_o_sharedMainInstance = nil;
long i;
for( i = 0; i < [[self options] count]; i++)
{
VLCTreeItem * item = [[self options] objectAtIndex:i];
VLCTreeLeafItem * item = [[self options] objectAtIndex:i];
VLCConfigControl *control;
control = [VLCConfigControl newControl:[item configItem] withView:view];
......@@ -632,11 +667,6 @@ static VLCPrefs *_o_sharedMainInstance = nil;
if(!_options) _options = [[NSMutableArray alloc] init];
return _options;
}
- (module_config_t *)configItem
{
return _configItem;
}
@end
#pragma mark -
......
......@@ -1017,8 +1017,8 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
- (char *)stringValue
{
return strdup( [[VLCMain sharedInstance] delocalizeString:
[o_textfield stringValue]] );
return [[VLCMain sharedInstance] delocalizeString:
[o_textfield stringValue]];
}
@end
......@@ -1282,10 +1282,10 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
continue;
unsigned int confsize;
unsigned int unused;
module_config_get( p_parser, &confsize );
module_config_t *p_configlist = module_config_get( p_parser, &confsize );
for ( i = 0; i < confsize; i++ )
{
module_config_t *p_config = module_config_get( p_parser, &unused ) + i;
module_config_t *p_config = &p_configlist[i];
/* Hack: required subcategory is stored in i_min */
if( p_config->i_type == CONFIG_SUBCATEGORY &&
p_config->value.i == p_item->min.i )
......@@ -1299,6 +1299,7 @@ o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
[o_popup selectItem:[o_popup lastItem]];
}
}
module_config_free( p_configlist );
}
}
module_list_free( p_list );
......@@ -2033,12 +2034,12 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
continue;
unsigned int confsize;
module_config_get( p_parser, &confsize );
module_config_t *p_configlist = module_config_get( p_parser, &confsize );
for ( i = 0; i < confsize; i++ )
{
unsigned int unused;
module_config_t *p_config = module_config_get( p_parser, &unused ) + i;
module_config_t *p_config = &p_configlist[i];
NSString *o_modulelongname, *o_modulename;
NSNumber *o_moduleenabled = nil;
......@@ -2062,6 +2063,7 @@ if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
o_moduleenabled, nil]];
}
}
module_config_free( p_configlist );
}
module_list_free( p_list );
......
......@@ -574,6 +574,7 @@ create_toolbar_item( NSString * o_itemIdent, NSString * o_name, NSString * o_des
* hotkeys settings *
********************/
const struct hotkey *p_hotkeys = p_intf->p_libvlc->p_hotkeys;
[o_hotkeySettings release];
o_hotkeySettings = [[NSMutableArray alloc] init];
NSMutableArray *o_tempArray_desc = [[NSMutableArray alloc] init];
i = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment