mirror of
				https://github.com/owntone/owntone-server.git
				synced 2025-10-29 15:55:02 -04:00 
			
		
		
		
	readlock on db_find. a db_find during a background rescan apparently kills the db handle. still a small race there, need to rethink locking altogether.
This commit is contained in:
		
							parent
							
								
									90e50f9818
								
							
						
					
					
						commit
						cbfbd9990f
					
				| @ -422,7 +422,10 @@ int db_end_initial_update(void) { | |||||||
| 
 | 
 | ||||||
|     rbdestroy(db_removed); |     rbdestroy(db_removed); | ||||||
| 
 | 
 | ||||||
|  |     DPRINTF(E_DBG,L_DB,"Reorganizing db\n"); | ||||||
|     gdbm_reorganize(db_songs); |     gdbm_reorganize(db_songs); | ||||||
|  |     gdbm_sync(db_songs); | ||||||
|  |     DPRINTF(E_DBG,L_DB,"Reorganize done\n"); | ||||||
|     db_unlock(); |     db_unlock(); | ||||||
| 
 | 
 | ||||||
|     return 0; |     return 0; | ||||||
| @ -1160,21 +1163,37 @@ int db_playlist_items_enum_end(ENUMHANDLE handle) { | |||||||
| MP3FILE *db_find(int id) {  /* FIXME: Not reentrant */ | MP3FILE *db_find(int id) {  /* FIXME: Not reentrant */ | ||||||
|     MP3FILE *pmp3=NULL; |     MP3FILE *pmp3=NULL; | ||||||
|     datum key, content; |     datum key, content; | ||||||
|  |     int is_locked=0; | ||||||
| 
 | 
 | ||||||
|     key.dptr=(char*)&id; |     key.dptr=(char*)&id; | ||||||
|     key.dsize=sizeof(int); |     key.dsize=sizeof(int); | ||||||
| 
 | 
 | ||||||
|  |     if(!db_update_mode) { | ||||||
|  | 	db_readlock(); /** \todo fix race */ | ||||||
|  | 	is_locked=1; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     content=gdbm_fetch(db_songs,key); |     content=gdbm_fetch(db_songs,key); | ||||||
|     MEMNOTIFY(content.dptr); |     MEMNOTIFY(content.dptr); | ||||||
|     if(!content.dptr) |     if(!content.dptr) { | ||||||
|  | 	DPRINTF(E_WARN,L_DB,"Could not find id %d\n",id); | ||||||
|  | 	if(is_locked) | ||||||
|  | 	    db_unlock(); | ||||||
| 	return NULL; | 	return NULL; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     pmp3=(MP3FILE*)malloc(sizeof(MP3FILE)); |     pmp3=(MP3FILE*)malloc(sizeof(MP3FILE)); | ||||||
|     if(!pmp3) |     if(!pmp3) { | ||||||
|  | 	DPRINTF(E_LOG,L_MISC,"Malloc failed in db_find\n"); | ||||||
|  | 	if(is_locked) | ||||||
|  | 	    db_unlock(); | ||||||
| 	return NULL; | 	return NULL; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     db_unpackrecord(&content,pmp3); |     db_unpackrecord(&content,pmp3); | ||||||
|     free(content.dptr); |     free(content.dptr); | ||||||
|  |     if(is_locked) | ||||||
|  | 	db_unlock(); | ||||||
|     return pmp3; |     return pmp3; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user